AS 3 Flash倒数计时器,用于游戏画面显示

问题描述:

我目前正在使用动作脚本3参加Flash游戏编程课程,似乎无法找到倒计时然后执行动作的任何地方的时钟.我一直在使用Lynda教程,但并没有帮助,我也对Google进行了很多搜索,但没有运气.我有一个倒计时时钟,已经尝试过"if"语句,但是没有运气.

I am currently in a Flash game programming class with action script 3 and can't seem to find a clock anywhere that counts down and then does an action. I've been using Lynda tutorials and that hasn't been helpful and I have also Google searched quite a bit, but no luck. I have a Countdown clock and have been try "if" statements, but no luck.

有人可以在正确的方向上指导我做错什么吗?

Can someone guide me in the right direction on what I am doing wrong?

 //game timer

 var count:Number = 60; // amount of time 

 var myTimer:Timer = new Timer(1000,count); // time in ms, count is calling from line above

 myTimer.addEventListener(TimerEvent.TIMER, countdown);

 myTimer.start();

 function countdown(event:TimerEvent):void
 {
     myText_txt.text = String((count)-myTimer.currentCount); //dynamic txt box shows current count 
 }


 //if and else if statements

 if (((count)-myTimer.currentCount) == 58)
 {
     gotoAndStop(2);
 }

这应该有所帮助;)没有任何魔幻数字.

This should help ;) Without any magic numbers.

var myTimer:Timer = new Timer(1000,60); // every second for 60 seconds
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
myTimer.start();

function onTimer(e: TimerEvent):void {
    myText_txt.text = String(myTimer.repeatCount - myTimer.currentCount);
}

function onComplete(e: TimerEvent):void{
    gotoAndStop(2);
}