سؤال

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

نصائح أخرى

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);
     }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top