I am learning how to make a timer to my game. It is something like "Who wants to be a millionaire?" I have 15 questions. There is timer for each question:60 seconds.... When I click on an answer I go on next frame, but my timer does not stop. What should I add ( and where ) to stop my timer when I clik an answer? (Flash Professional CS 5/ ActionScript 2) My code for the timer is:
timer = 60;
countdown = function(){
_root.timer--;
if(_root.timer<=0){
gotoAndPlay(20); stop();
}
}
countdownInterval = setInterval(countdown,1000);
Try this
var timer:Timer = new Timer();
public function startTimer(n:Number):void{ //n = number of seconds you want to run the timer
t.repeatCount = n;
t.start();
t.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
}
public function timerComplete(event:TimerEvent):void{
t.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);
//What ever you want to do when timer is up.
}
Hope it helped!