【问题标题】:Actionscript 2 timer decreases fastActionscript 2 计时器快速减少
【发布时间】:2012-08-14 09:35:31
【问题描述】:

所以,我在 2 个场景中有这个计时器。第一个场景中的计时器完美运行。然而,当我尝试到第二个场景时,计时器变得如此之快。 我有 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 秒。我只是不知道是什么导致计时器在第二个场景中快速减少。你怎么看?

【问题讨论】:

    标签: javascript actionscript actionscript-2 flash-cs5


    【解决方案1】:

    在第二个场景中,timer 递减速度快了 2 倍,因为有两个 setInterval 运行,_root.timer 将在两个阶段等于 timer。所以每秒有两个函数调用,并且每个函数都减少相同的变量。

    解决方法:在第二个场景中,将定时器变量重命名为 timer2 或 timernew。

    【讨论】:

    • 知道了。谢谢。嗯,可以暂停和播放计时器吗?我的意思是玩,而不是重置它。它会在停止的地方播放。也许,通过使用按钮。非常感谢。
    • 我不知道 AS2 定时器的实现,但在 AS3 中它很容易,用 new Timer() 创建定时器对象;只需使用 timer.reset();计时器.start();但是如果你把函数定义为全局的,那么 clearInterval 和 setInterval 就很容易了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多