【发布时间】:2015-05-17 11:16:56
【问题描述】:
我在名为 _countDownTimer 的 AS3 类中有一个私有 Timer 对象。
当类被实例化时,我也会像这样以任意延迟初始化 Timer 一次
_countDownTimer =new Timer(10000, 1);
_countDownTimer.addEventListener(TimerEvent.TIMER, onCue,false,0,true);
问题是每次定时器运行时我都需要更改延迟时间。
所以在另一种方法中,我首先重新定义一个私有变量_newDelayTime,然后调用startMyTimer() 重新定义延迟并启动_countDownTimer。
我的问题是,这应该正常工作吗?
每次更改延迟时,我是否还需要实例化一个新的 _countDownTimer 并重新添加监听器?
private function startMyTimer():void{
_countDownTimer.reset();
_countDownTimer.stop();
_countDownTimer.delay=_newDelayTime;
_countDownTimer.start();
}
private function onCue(e:TimerEvent):void{
trace('do stuff');
}
【问题讨论】:
标签: actionscript-3 flash timer