A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How to make a smooth movement (at the end, on release) using drag?

  1. #1
    Senior Member
    Join Date
    Sep 2006
    Posts
    248

    Unhappy How to make a smooth movement (at the end, on release) using drag?

    Hello everyone!
    I am struggling with the smooth movement of my MC.
    I am able to move it around, but want to make it smooth, like google maps or something like that. Right now, it looks very "abrupt" at the end. I am looking for something called drag and throw, i guess. Where when the user releases the mc, it still moves a bit until stops. But i cant use on EnterFrame, since i dont want to keep calling it over and over.
    Here is the code that i am using:
    Code:
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
    mc_square.addEventListener(MouseEvent.MOUSE_DOWN, start_drag);
    mc_square.addEventListener(MouseEvent.MOUSE_UP, stop_drag);
    
    function mouseMoveHandler(evt:MouseEvent):void
    {
        //Here i have my own cursor.
                //mc_my_cursor.x = evt.stageX;
                //mc_my_cursor.y = evt.stageY;
    }
    
    function start_drag(e:MouseEvent):void
    {
            mc_square.startDrag();
    }
            
    function stop_drag(e:MouseEvent):void
    {
            mc_square.stopDrag();
    }
    Any ideas, sugestions, hints, ANYTHING, will be welcome!
    Kind regards,
    Leo.

  2. #2
    Member
    Join Date
    May 2012
    Posts
    51
    When you make changes to the display list in a mouse move handler, you typically want to call updateAfterEvent(). Your custom cursor should move more smoothly if you do that.

    At the end of the drag, what I usually do is use a Tween object to move the object to its final position.
    Last edited by cleong; 08-19-2012 at 06:29 PM.

  3. #3
    Senior Member
    Join Date
    Sep 2006
    Posts
    248
    Hello Cleong,
    Thanks for the reply.
    How would u move something at the end of the drag? Isnt that mc already at the end?
    I mean, there is no start point, just end point when the user releases the mouse button.
    Could u provide an example?

    Thanks,
    Regards,
    Leo.

  4. #4
    Member
    Join Date
    May 2012
    Posts
    51
    Perhaps I didn't understand you correctly. A typical problem often encounter in drag-and-drop if that we don't want the movie-clip to suddenly appear in the drop slot. Tweening it there makes it look less abrupt.

  5. #5
    Senior Member
    Join Date
    Sep 2006
    Posts
    248
    Thanks Cleong for your reply,
    But i still dont understand how can i make a tween without the start point, i just have the end point... and cant use the onEnterFrame..

    Any help would be welcome!

    Thanks!

    Leo.

  6. #6
    Member
    Join Date
    May 2012
    Posts
    51
    The start point would be where the movie-clip is when the release occurs.

  7. #7
    Senior Member
    Join Date
    Sep 2006
    Posts
    248
    But the release happens when the movement stops, right?
    Thats the issue... both are the same.
    I pasted a code that i am using...

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