Multiple timers with different delays > mutliple events on complete?
I use several timers with different delays at once. Unfortunately, the timer class is not documented.
What's the best solution, to fire specific events on TimerEvent.TIMER_COMPLETE
?
var _timer:Object = new Timer(_m开发者_如何学CyVAR*1000,1);
_timer.addEventListener(TimerEvent.TIMER_COMPLETE, eventTimerHandler);
_timer.start();
...
private function eventTimerHandler(event:TimerEvent):void
{
event.target.removeEventListener(TimerEvent.TIMER_COMPLETE, eventTimerHandler);
event.target.reset();
event.target.stop();
// Fire specific event
}
You can create a custom Timer class by extending Timer class:
package {
import flash.utils.Timer;
public class CustomTimer extends Timer {
public var name : String;
public function CustomTimer(name: String,delay : Number, repeatCount : int = 0) {
super(delay, repeatCount);
this.name = name;
}
}
}
Then :
var customTimer:CustomTimer=new CustomTimer("foo",1000);
...
(if event.target.name == "foo")...
精彩评论