topical media & game development
animation-ch08-Easing2.ax
animation-ch08-Easing2.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class @ax-animation-ch08-Easing2 extends Sprite
{
private var ball:animation_ch08_Ball;
private var easing:Number = 0.2;
private var targetX:Number = stage.stageWidth / 2;
private var targetY:Number = stage.stageHeight / 2;
public function @ax-animation-ch08-Easing2()
{
init();
}
private function init():void
{
ball = new animation_ch08_Ball();
addChild(ball);
ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onMouseDown(event:MouseEvent):void
{
ball.startDrag();
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseUp(event:MouseEvent):void
{
ball.stopDrag();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onEnterFrame(event:Event):void
{
var vx:Number = (targetX - ball.x) * easing;
var vy:Number = (targetY - ball.y) * easing;
ball.x += vx;
ball.y += vy;
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.