AS 3 Flash Countdown Timer For Game Over Screen

非 Y 不嫁゛ 提交于 2019-12-24 09:43:58

问题


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);
 }

回答1:


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);
}



回答2:


Add your if statement inside countdown like so:

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);
     }
}


来源:https://stackoverflow.com/questions/22141106/as-3-flash-countdown-timer-for-game-over-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!