2009. február 17., kedd

Actionscript 3.0 - Interactive-animation

var myTimer:Timer = new Timer(20);
myTimer.addEventListener(TimerEvent.TIMER, moveBall);
stage.addEventListener(MouseEvent.MOUSE_DOWN, triggerTimer);

var speed:Number = 20;
var startX:Number;
var startY:Number;
var endX:Number;
var endY:Number;
var i:Number;

function triggerTimer(event:MouseEvent):void
{
startX = ball_mc.x;
startY = ball_mc.y;
endX = stage.mouseX;
endY = stage.mouseY;
i = 0;
myTimer.start();
}

function moveBall(event:Event):void
{
if(i < speed)
{
ball_mc.x += (endX - startX) / speed;
ball_mc.y += (endY - startY) / speed;
}
else
{
myTimer.stop();
}
i++;
}

Nincsenek megjegyzések: