A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 startDrag x y coordinates

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    16

    AS3 startDrag x y coordinates

    Hey guys, not sure if this is possible but i'd like to get the X,Y coordinates of a button I drag. here's my problem:

    PHP Code:
    backbutton_btn.addEventListener(MouseEvent.MouseDownbackbuttonDown);
    backbutton_btn.addEventListener(MouseEvent.MouseMovebackbuttonMove);

    public function 
    backbuttonDown(e:MouseEvent)
            {
                
    backbutton_btn.startDrag();
            }

    public function 
    backbuttonMove(e:MouseEvent)
            {
                
    trace(backbutton_btn.+","+backbutton_btn.y);

    the x and y coordinates remain the same even though i'm clearly dragging my button all over the stage. I did code my own by putting events and whatnot around the button but startDrag seemed smoother and faster. is it even possible?

  2. #2
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    You're doing it wrong.

    Code:
    backbutton_btn.addEventListener(MouseEvent.MouseDown, backbuttonDown); 
    backbutton_btn.addEventListener(MouseEvent.MouseMove, backbuttonMove); 
    
    public function backbuttonDown(e:MouseEvent) 
            { 
                e.target.startDrag(); 
            } 
    
    public function backbuttonMove(e:MouseEvent) 
            { 
                trace(e.stageX +","+e.stageY); 
    }

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    16
    Quote Originally Posted by illustratedlife
    You're doing it wrong.

    PHP Code:
    backbutton_btn.addEventListener(MouseEvent.MouseDownbackbuttonDown); 
    backbutton_btn.addEventListener(MouseEvent.MouseMovebackbuttonMove); 

    public function 
    backbuttonDown(e:MouseEvent
            { 
                
    e.target.startDrag(); 
            } 

    public function 
    backbuttonMove(e:MouseEvent
            { 
                
    trace(e.stageX +","+e.stageY); 

    hmmm...this does work, but I still don't understand why the x and y coordinates of my button remain at 0,0 and now I have to rely on the mouse event to report where it is at. maybe what i'm doing isn't the most popular thing, I just think it's cool to drag programmatic buttons around.

  4. #4
    Member
    Join Date
    Feb 2008
    Posts
    53

    Question how about locking a drag and drop object in with boundries?

    new to the forum. still somewhat green to AS3. hello all.

    i was reading this post (i found while doing a search to answer my question) and thought i'd ask you this here.

    how would i lock in an object into set boundries? i can do this in AS2 but can't get it to work in 3.

    in a nut shell, i have a ball. i want to drag this ball around the screen, but when it gets to the edge i don't want it to get cut off but instead stop at edge of the ball. essentially the stage is a box.

    here's what i got so far:
    ball_mc.buttonMode = true;
    ball_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    ball_mc.addEventListener(MouseEvent.MOUSE_UP, drop);

    function drag(event:Event):void
    {
    ball_mc.startDrag();
    }

    function drop(event:Event):void
    {
    ball_mc.stopDrag();
    }
    so how do i set the boundries in which i want the ball to stay?

    thanks!
    `shields

  5. #5
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    The LiveDocs are your friend.

    In AS3 it's done with a rectangle. Lookup startDrag in the LiveDocs index for the exact syntax.

  6. #6
    Member
    Join Date
    Feb 2008
    Posts
    53
    awesome! thanks illustratedlife. that was pretty easy to figure out once you told me what to look for.

  7. #7
    Member
    Join Date
    Feb 2008
    Posts
    53
    sorry tried to go back and add this to my previous post but couldn't find the edit button.

    so this is what i did:
    ball_mc.buttonMode = true;
    ball_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    ball_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
    var rectangle:Rectangle = new Rectangle(17, 17, 515, 365);

    function drag(event:Event):void
    {
    ball_mc.startDrag(true, rectangle);
    }

    function drop(event:Event):void
    {
    ball_mc.stopDrag();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center