AS3 Timer class [closed]
I need to create a timer using as3 timer class or some other class. And every 10 second i want to do some alert or trace something. Timer wont stop at any time. And every 10 second we can do some stuff.
The class of course would be the Timer class.
Here is a simple example to get you started.
package
{
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
public class TimerExample extends Sprite
{
public function TimerExample()
{
var timer:Timer = new Timer(10000);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
public function timerHandler(event:TimerEvent):void
{
trace("timerHandler: " + event);
}
}
}
Couldn't be simpler:
var t:Timer = new Timer(10000);
t.addEventListener("timer", doSomething);
t.start();
function doSomething(event:*):void {
trace("something");
}
精彩评论