我无法让我的计时器更快地进行测试

时间:2013-05-31 04:19:13

标签: actionscript-3

嘿伙计们,我想让这个倒数计时器更快,所以我可以测试它进入下一级别等...但我正在玩数字,但它不起作用:(

如果你们可以评论你们正在做什么,我很喜欢编程并帮助我

package {
import flash.events.TimerEvent;
import flash.utils.Timer;

public class CountdownTimer extends Timer {

    public var time:Number = 0;

    public function CountdownTimer(time:Number = Number.NEGATIVE_INFINITY, delay:Number = 1000) {
        super(delay, repeatCount);

        if (isNaN(time)) {
            this.time = 0;
        }
        else {
            this.time = time;
        }
        repeatCount = Math.ceil(time / delay);
    }

启动计时器

    override public function start():void {
        super.start();

        addEventListener(TimerEvent.TIMER, timerHandler);
        addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
    }

重置计时器

    override public function reset():void {
        super.reset();
        time = 0;

    }

    protected function timerHandler(event:TimerEvent):void {
        time -= delay;
        if(time == 0){
        trace("time = 0")
        }
        trace("delay");
        trace(time);
    }

此标准是完成计时器

    protected function timerCompleteHandler(event:TimerEvent):void {

    }

停止计时器

    override public function stop():void {
        super.stop();

        removeEventListener(TimerEvent.TIMER, timerHandler);
        removeEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
    }

}
}

1 个答案:

答案 0 :(得分:0)

    var timer:Timer = null;

    timer = new Timer(delay);
    timer.addEventListener(Timer.TimerEvent, _OnTimerFire);

   private function _OnTimerFire(e:TimerEvent) : void {
     // do stuff
   }

延迟是计时器被撤销之前的毫秒数。我不确定为什么你必须继承定时器类。