Actionscript 3.0 - drag and throw with easing
- by Joe Hamilton
I'm creating a map in flash and I would like to have a smooth movement similar to this:
http://www.conceptm.nl/
I have made a start but I'm having trouble taking it to the next stage.
My code currently throws the movieclip after the mouse is release but there is no easing while the mouse button is down.
Any tips on how I would achieve this?
Here is my current code:
// Vars
var previousPostionX:Number;
var previousPostionY:Number;
var throwSpeedX:Number;
var throwSpeedY:Number;
var isItDown:Boolean;
// Event Listeners
addEventListener(MouseEvent.MOUSE_DOWN, clicked);
addEventListener(MouseEvent.MOUSE_UP, released);
// Event Handlers
function clicked(theEvent:Event) {
isItDown =true;
addEventListener(Event.ENTER_FRAME, updateView);
}
function released(theEvent:Event) {
isItDown =false;
}
function updateView(theEvent:Event) {
if (isItDown==true){
throwSpeedX = mouseX - previousPostionX;
throwSpeedY = mouseY - previousPostionY;
mcTestMovieClip.x = mouseX;
mcTestMovieClip.y = mouseY;
}
else{
mcTestMovieClip.x += throwSpeedX;
mcTestMovieClip.y += throwSpeedY;
throwSpeedX *=0.9;
throwSpeedY *=0.9;
}
previousPostionX= mcTestMovieClip.x;
previousPostionY= mcTestMovieClip.y;
}