topical media & game development
animation-ch07-MouseMoveDrag.ax
animation-ch07-MouseMoveDrag.ax
[swf]
[flash]
flex
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class @ax-animation-ch07-MouseMoveDrag extends Sprite
{
private var ball:animation_ch07_Ball;
public function @ax-animation-ch07-MouseMoveDrag()
{
init();
}
private function init():void
{
ball = new animation_ch07_Ball();
ball.x = 100;
ball.y = 100;
addChild(ball);
ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private function onMouseDown(event:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseUp(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(event:MouseEvent):void
{
ball.x = mouseX;
ball.y = mouseY;
}
}
}
(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.