Advertisement |
var myTimer:Timer = new Timer(1000, 10);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, sayHello);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, sayBye);
function sayHello(e:TimerEvent):void
{
trace("hello");
trace("Current Count: " + myTimer.currentCount);
}
function sayBye(e:TimerEvent):void
{
trace("bye");
}
So in the example above, the Timer will count 10 times. Each time it makes a count, the word hello will come out in the output window, and the currentCount value will increase by 1. Once it reaches 10, then the TimerEvent.TIMER_COMPLETE event gets dispatched, and you will see the word bye come out in the output window.
And that concludes this AS3 Timer - ActionScript 3 tutorial.
0 comments: