Another problem with countdown timer.  Don't know why

Hi all

I noticed on my 30 minutes to count down the seconds seem to ignore or hesitate at different intervals.  It seems to work for 30 minutes, but it will be displayed on a GIANT screen and the seconds of the movements is very obvious.  Someone would show me how please correct the code to a total accuracy of the calendar?  Not sure if I should add milliseconds.  (I don't want to show in the timer, just minutes and seconds 00:00.  Thanks in advance.

Here is the code

totalTime = 1800;

Start from 30 minutes

startTime = getTimer();

function timer() {}

timeLeft = (totalTime * 1000)-(getTimer () - startTime);

seconds = Math.floor (timeLeft/1000);

minutes = 0;

While (seconds > 59) {}

seconds = seconds-60;

minutes = minutes + 1;

}

If (minutes < 10) {}

minutes = String("0"+minutes);

}

If (seconds < 10) {}

seconds = String ("0" + seconds);

}

Time_text. "Text = minutes +": "+ seconds;

If (timeLeft < = 0) {}

Time_text. Text = ("00:00");

_root.gotoAndPlay (11);

clearInterval (timer1);

}

}

Timer1 = setInterval (timer, 1000);

You walk a fine line with a 1 second interval.  Increase your sampling rate and you are less likely to ignore a value.  Here is an approach that samples at rate of the file.  Note that 'var' has been addded in many places.  You should always declare your variables without worrying that AS2 allows you to not have to.

totalTime var = 1800;

Start from 30 minutes

startTime = getTimer() var;

this.onEnterFrame = function() {}

timeLeft var = (totalTime * 1000)-(getTimer () - startTime);

var seconds = Math.floor (timeLeft/1000);

var minutes = Math.floor (seconds/60);

seconds = seconds % 60;

If (minutes<10)>
minutes = String("0"+minutes);
}

If (seconds<10)>
seconds = String ("0" + seconds);
}

Time_text. "Text = minutes +": "+ seconds;

If (timeLeft<=0)>
delete this.onEnterFrame;
Time_text. Text = ("00:00");
_root.gotoAndPlay (11);
}
}

Tags: Adobe Animate

Similar Questions

Maybe you are looking for