How to use a Timer in Actionscript 3

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.

var myTimer:Timer = new Timer(1000);
Code language: JavaScript (javascript)

Setup an event listener to call a function.

myTimer.addEventListener("timer", myTimerEventHandler);
Code language: JavaScript (javascript)

Start the Timer.

myTimer.start();
Code language: CSS (css)

Start the Timer.

function myTimerEventHandler(event:TimerEvent):void { trace(myTimer.currentCount+" seconds have passed."); }
Code language: JavaScript (javascript)

So altogether we have this.

var myTimer:Timer = new Timer(1000); myTimer.addEventListener("timer", myTimerEventHandler); myTimer.start(); function myTimerEventHandler(event:TimerEvent):void { trace(myTimer.currentCount+" seconds have passed."); }
Code language: JavaScript (javascript)

Now you know how to use a Timer in Actionscript 3.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments