我在我创建的if
语句上遇到了麻烦。看不出为什么它不起作用,所以希望一些新鲜的眼睛可能会有所帮助!
我有一个计时器:
var delayTimer:Timer = new Timer(9000,1);
和另一帧上的功能
delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timesUp);
function timesUp(evt:TimerEvent):void
{
if (delayTimer.currentCount == 9)
{
trace.("which it does")
incorrect.stop();
timesup.play();
}
else
{
incorrect.play();
timesup.stop();
}
}
我的示踪剂似乎没有增加,所以显然我的功能出现了出现问题。incorrect
和timesup
都是我需要在计时器= 9时播放的电影剪辑。因此,如果计时器用完,它将播放电影剪辑times up
而不是incorrect
。
如果其他使用相同结构但有效的语句,我还有其他一些,所以我对此有些困惑。
Timer.currentCount
is "自从零以零开始以来,计时器已经发射的总数" 。正如您在构造函数中指定的那样,计时器重复一次,currentCount
将永远不会达到9。
您可能想做的就是在计时器实际用完时简单地触发9000毫秒后。这正是TIMER
事件所做的。当延迟结束并且计时器发射时,它将发射。该事件将在您的情况下发射一次,因为您指定了计时器只能运行一次(currentCount
为0
,它将发射一次)。TIMER_COMPLETE
事件将在所有重复结束之后,在您的情况下,在签发TIMER
事件之后,将在结尾处发射一次。
回答您的评论,这是我的做法(以及我如何理解您要做的事情):
var delayTimer:Timer = new Timer(9000, 1);
delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timesUp);
function timesUp (evt:TimerEvent):void
{
// after the timeout
incorrect.stop();
timesup.play();
}
// start the timer
delayTimer.start();
// start the animation, that occurs while the timer runs
incorrect.play();
timesup.stop();