package { import flash.display.Sprite; import flash.utils.Timer; import flash.events.TimerEvent; import flash.utils.getTimer; public class animation_ch19_Timer2 extends Sprite { private var timer:Timer; private var ball:animation_ch19_Ball; public function animation_ch19_Timer2() { init(); } //@ init(s) private function init():void { stage.frameRate = 1; ball = new animation_ch19_Ball(); ball.y = stage.stageHeight / 2; ball.vx = 5; addChild(ball); timer = new Timer(20); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } //@ timer(s) private function onTimer(event:TimerEvent):void { ball.x += ball.vx; event.updateAfterEvent(); } } }