Reputation: 17
I'm making a quiz game, there's 5 questions involved. I made a timer for the 1st question so when the user hasnt answered the question within 10secs they'll go to question 2 (another frame).
Question 1 timer works fine, how do i get question 2 to do the exactly the same as question 1? I tried adding the same code into question 2 however it gives me an error.
Thanks
My code:
stop();
var count:Number = 10;
var myTimer:Timer=new Timer(1000,2);
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.start();
function countdown(event:TimerEvent):void {
count00.text=String((count)-myTimer.currentCount);
if(count00.text == "0"){
gotoAndStop(85);
}
}
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, countdown);
Upvotes: 0
Views: 1427
Reputation: 1531
First off, you shouldnt be doing this over multible frames. But thats a different discussion.
You should stop your timer, remove the listener and move to next a frame in an onComplete event.
stop();
var count:Number = 10;
var myTimer:Timer=new Timer(1000,count);// this should be the total count
myTimer.addEventListener(TimerEvent.TIMER, countdown);
myTimer.addEventListener(TimeEvent.TIMER_COMPLETE, timerDone);
myTimer.start();
function countdown(event:TimerEvent):void {
count00.text=String((count)-event.currentTarget.currentCount);//get currentCount from event
}
function timerDone(e:TimerEvent):void{
trace("Timer finishing!");
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, countdown);
gotoAndStop(85);
}
Btw. you are setting the repeatCount of the timer to 2, new Timer(1000,2);
this will give you 2 seconds countdown, not much time for a question ;) it should be count
Also there musst be a dynamic textField with the instance name count00
in the same frame (not layer) as the code!!
Please always include relevant error messages in the question!
Upvotes: 1