How to make a click and drag formulary in Flash

Subscribe to How to make a click and drag formulary in Flash 7 posts

avatar for hurricane112233 hurricane112233 29 posts
Flag Post

Hi everyone!

I’m trying to make a box that contains a formulary. I’ve already built this box with it’s texts, text boxes, buttons, images…

Now, I discovery that it’s possible to drag this box using Action.
The code is something like this:

on(Press) = function(){
startDrag(this);
}
on(Release) = function(){
stopDrag();
}

I’ve done and it worked well!

But my problem is that doing it, I became unable to write things on the formulary and press the buttons.

So, I want to know if there’s any way to do a box with a formulary in it that can be dragged (that doesn’t jeopardize my form…)

I dislike to make Actions, so if there’s any way to do it in ActionScrips (classes), I would be glad!

 
avatar for feartehstickman feartehstickman 521 posts
Flag Post
var dx:int;
var dy:int
var dragging:Boolean;
object.addEventListener(MouseEvent.MOUSE_DOWN,_onMouseDown)
object.addEventListener(MouseEvent.MOUSE_UP,_onMouseUp)
addEventListener(Event.ENTER_FRAME,_onEnterFrame)
function _onMouseDown(event:MouseEvent){
    dx = object.x - mouseX;
    dy = object.y - mouseY;
    dragging = true;
}
function _onMouseUp(event:MouseEvent){
    dragging = false;
}
function _onEnterFrame(event:Event){
    if(dragging){
        object.x = mouseX + dx;
        object.y = mouseY + dy;
    }
}

I’m pretty sure that this is not the right argument for startDrag()

startDrag(lockCenter:Boolean = false, bounds:Rectangle = null):void
It should be, this.startDrag(); this.stopDrag();

 
avatar for hurricane112233 hurricane112233 29 posts
Flag Post

I love this way you did it, feartehstickman, tks!

But do you know how to make it in Action Script 2?
And how to import the MouseEvent in the Action Script 2?

Because I’ve started my project in AS2, not in AS3…

tks!

 
avatar for Senekis93 Senekis93 4090 posts
Flag Post

fearthestickman: It’d be better to use a mouseMove listener instead of the boolean/frame thing.

 
avatar for hurricane112233 hurricane112233 29 posts
Flag Post

I found the sollution:
(I’ll replace the _ symbol to the \ becaus kongregate changes it to italic)


class Form extends Movieclip{
   function onLoad(){
      \root.form.onMouseDown = function(){
         var f\wh\2 = \width / 2;
         var f\ht\2 = \height / 2;
         if((\xmouse > 0 – f\wh\2 && \xmouse < f\wh\2)&&(\ymouse > 0 -f\ht\2 && \ymouse < f\ht\2)){
            this.startDrag();
            trace(“inside”);
         }else{
            trace(“outside”);
         }
      }
      \root.fundo.onMouseUp = function(){
         this.stopDrag();
      }
   }
}

 
avatar for hurricane112233 hurricane112233 29 posts
Flag Post

Here is the game I was doing:
http://www.kongregate.com/games/hurricane112233/snake

The option menu is dragable…

 
avatar for feartehstickman feartehstickman 521 posts
Flag Post
Originally posted by Senekis93:

fearthestickman: It’d be better to use a mouseMove listener instead of the boolean/frame thing.

Ah ok. I didn’t know that was a thing, but it would make everything easier. Thankyou.