Skip to main content
Known Participant
October 22, 2010
Question

Drag and Drop with smooth move...Tween?

  • October 22, 2010
  • 2 replies
  • 4434 views

Hi all, well I just start to learn AS3 and I use simple MC with CODE SNIPPET for Drag and Drop action, so is anyone know how can I make effect after I drag MC that MC make smooth movement after drop...with tweener or and how?

Here is my snippet code:


movieClip_1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
    movieClip_1.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
    movieClip_1.stopDrag();
}

Thanks for any help

This topic has been closed for replies.

2 replies

SEA_ElvirAuthor
Known Participant
October 23, 2010

I find exactly what Im trying to do, but only to drag map with zoom: http://activeden.net/item/interactive-map-as3-v2/full_screen_preview/102048

Ned Murphy
Legend
October 23, 2010

It's not clear what you want to do in terms of moving the movieclip after dropping it, but here's a somewhat quick way to get acquainted... using the built-in Tween class.

import fl.transitions.Tween;
import fl.transitions.easing.*;

function fl_ReleaseToDrop(event:MouseEvent):void
{
    movieClip_1.stopDrag();

     var tweenMC:Tween = new Tween(movieClip_1, "x", Regular.easeIn, movieClip_1.x, movieClip_1+100, 2.0, true);
}

That line of code will move the movieclip from where you dropped it to 100 pixels to the right of it in 2.0 seconds.

Most people here will recommend using a third party tweening class such as Tweenlite.  If you are already familiar with using a third party tweening class such as tweenlite or tweener, then you should be able to substitute the code for what was done.  If you are not familiar with the thrid party classes, then you need to download them and place them in your classpath to make them useable (as well as become familiar with how to code for them).

SEA_ElvirAuthor
Known Participant
October 23, 2010

thank you on your answer, but I have to say that Im very new in all this and code that you write when I drag MC it go very left and cant move right anymore, but here is example what Im talking about, but just without bounce http://www.theorigin.net/tutorialFiles/HockeyPuck/hockeypuck.swf

thanks,

Ned Murphy
Legend
October 23, 2010

That example really is not any clearer than your explanation of what you want.  You mentioned something about wanting a smooth move, and a tween will do that, but what you mean as far as where it will smoothly move to is not explained.

var tweenMC:Tween = new Tween(movieClip_1, "x", Regular.easeIn, movieClip_1.x, movieClip_1+100, 2.0, true);

In that line of code, movieClip_1.x is the location where you dropped the movieClip_1 (where you let go of the mouse button).

I see I made an error and intended to write the next parameter as   movieClip_1.x+100, which would move movieClip_1 100 pixels to the right of where you dropped it in 2 secs.

You can adjust that value to whatever you like 0, 10, 100, movieClip_1.x+30, etc...  As I said, you have not given any idea of where it is supposed to smoothly move to, so I just gave an example that you should be able to adjust as you need to.