开发者

Multiple timers with different delays > mutliple events on complete?

开发者 https://www.devze.com 2023-02-01 15:21 出处:网络
I use several timers with different delays at once. Unfortunately, the timer class is not documented.

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")...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号