Flash Timer events with Action Script 3

By Dario Gutierrez in Flash | Comments Comments

25 April 2009

This is my firs post and welcome to my blog, let me show you how use timer events with ActionScript 3.0.

The first step in using the Timer class is to create an instance of the class:

var timer:Timer = new Timer (delay:Number, repeatCount:int);

The class constructor takes two arguments, the first is mandatory, and specifies the delay, in milliseconds, before the timer event is fired. The second parameter is optional and is the number of times the event fires. Omitting the second parameter will cause the event to fire infinitely, each time after the especified delay, similar to prior setInterval() implementations. Using a positive value, such as 1, will cause the event to fire that many times (again after the specified delay), similar to prior setTimeout() implementations.

See the follow example:

var timer:Timer = new Timer (1000);

timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(evt:TimerEvent):void{
loader.rotation +=10;
}

Download the source file

Tags: , ,

  • Hi Franky, here is the live demo. Thanks for your comments!
  • I would have liked to at least see a demo! Cmon now!
blog comments powered by Disqus