Reputation: 71
I'm making a game in actionscript 3.0. I currently have a countdown timer (counts down from 30 seconds). Once the 30 seconds is up I want the frame to move from frame 2 to frame 3. I have put gotoAndStop(3)
in the code under the timer but when the timer starts it goes to frame 3 straight away. It doesnt go to frame 3 when the 30 seconds is up. I would appreciate any help at all!
var nCount:Number = 30;
var myTimer:Timer = new Timer(1000, nCount);
timer_text.text = nCount.toString(nCount);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, countdown);
function countdown(e:TimerEvent):void
{
nCount--;
timer_text.text = nCount.toString();
gotoAndStop(3);
}
Upvotes: 0
Views: 344
Reputation: 46027
You are calling gotoAndStop(3);
on the very first timer event, i.e. after one second since you are not checking the value of nCount
. You need to call gotoAndStop(3);
only when nCount
is zero.
function countdown(e:TimerEvent):void {
nCount--;
timer_text.text = nCount.toString();
if (nCount == 0) {
gotoAndStop(3);
}
}
Upvotes: 1