Actionscript 2计时器快速减少

时间:2012-08-14 09:35:31

标签: javascript actionscript actionscript-2 flash-cs5

所以,我在2个场景中有这个计时器。第一个场景中的计时器工作正常。然而,当我尝试它到第二个场景时,计时器进行得如此之快。 我有两组代码:

_root.timer = 10;
clearInterval(id);
id = setInterval (function ()
           { 
                _root.timer--;
                if(timer==0)
                {
                    gotoAndStop(65);
                }
           }, 1000); 

和此:

timer = 10;
timer.text= timer;
countdown = function(){
            timer--;
            if(timer==0){
                         clearInterval(countdownInterval);
                         gotoAndStop(65);
                        }
                      }
countdownInterval = setInterval(countdown,1000);

我知道1000毫秒= 1秒。我只是不知道是什么原因导致计时器在第二个场景中快速减少。你觉得怎么样?

1 个答案:

答案 0 :(得分:0)

在第二个场景中,定时器的速度降低了2倍,因为有两个setInterval在运行,_root.timer将在两个阶段中等于定时器。所以每秒调用两个函数,每个函数都会消除相同的变量。

在第二个场景中

解决方案:,将计时器变量重命名为timer2或timernew。