PDA

View Full Version : Timer acting funny


GrandMark
08-07-2004, 03:34 AM
I'm making a game. The user has 2 minutes to answer all 5 questions correctly, each question being a different frame label. A user answers one question, it goes to the next label, all while still maintaining the counter.

After all 5 questions are answered, it takes you to another label stating something like "go back and try again". So this takes you back to question 1. The problem is, the timer now counts down twice as fast. Each time the user is sent to the main frame that the counter code is on, it speeds it up x2. Anyway of maintaining the counter speed consistent?

Here's the code on frame 1:

function countDown() {
if (Math.round(outputMin)==0 && Math.round(outputSec)==0 || chk==1){
clearInterval(timer);
}else {
if (outputSec != "00") {
outputSec = Math.round(outputSec) - 1;
//trace(output);
}else {
outputSec = 59;
outputMin = Math.round(outputMin) -1;
}
if (outputSec <= 9 && outputSec > 0) {
outputSec ="0" + outputSec;

}else if (outputSec == 0) {
outputSec = "00";
}
if (outputSec == "00" && outputMin == "0"){
gotoAndStop("TimesUp);
}
}
}

chk=0;
stop();

timer = setInterval(countDown, 1000);

farafiro
08-08-2004, 01:52 PM
when the user answers the last Q, clear the setInterval function "clearInterval" and reset its components, and when he/she hits the goBack button, call it again

ericlin
08-08-2004, 04:03 PM
Maybe your script did not clear the interval. Becareful, your code tells that, when the outputSec==1, it goes to "TimesUp" frame and change outputSec=0, and after 1000 msec, the interval is cleared because of outputSec==0.

If you have script modifying the outputMin and outputSec at the "TimesUp" frame, then it is possible that the interval wont be cleared.