It is really easy to create a Timer in Actionscript 3.
Instantiate the Timer Class and pass a time in millions of 1000 to it to work in seconds.
1
|
var myTimer:Timer = new Timer(1000);
|
Setup an event listener to call a function.
1
|
myTimer.addEventListener("timer", myTimerEventHandler);
|
Start the Timer.
Start the Timer.
1
2
3
|
function myTimerEventHandler(event:TimerEvent):void {
trace(myTimer.currentCount+" seconds have passed.");
}
|
So altogether we have this.
1
2
3
4
5
6
|
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener("timer", myTimerEventHandler);
myTimer.start();
function myTimerEventHandler(event:TimerEvent):void {
trace(myTimer.currentCount+" seconds have passed.");
}
|
Now you know how to use a Timer in Actionscript 3.