Hi!
I’m integrating a timer based on a tutorial.
This timer works very well and it’s basic code is as follows:
_root.onEnterFrame = function() {
if (timing) {
//calculate values
elapsedTime = getTimer()-startTime;
//hours
elapsedHours = Math.floor(elapsedTime/3600000);
remaining = elapsedTime-(elapsedHours*3600000);
//minutes
elapsedM = Math.floor(remaining/60000);
remaining = remaining-(elapsedM*60000);
//seconds
elapsedS = Math.floor(remaining/1000);
remaining = remaining-(elapsedS*1000);
//hundredths
elapsedH = Math.floor(remaining/10);
//output to text box
//add a 0 on the front of the numbers
//if the number is less than 10
if (elapsedHours<10) {
hours = "0"+elapsedHours.toString();
} else {
hours = elapsedHours.toString();
}
if (elapsedM<10) {
minutes = "0"+elapsedM.toString();
} else {
minutes = elapsedM.toString();
}
if (elapsedS<10) {
seconds = "0"+elapsedS.toString();
} else {
seconds = elapsedS.toString();
}
if (elapsedH<10) {
hundredths = "0"+elapsedH.toString();
} else {
hundredths = elapsedH.toString();
}
_root.timer_txt = hours+":"+minutes+":"+seconds+":"+hundredths;
}
};
The code is placed on frame 1 of a layer called “actions”. The problem is when the movie goes to the next frame, the timer freezes, likely because the 2nd frame does not have the actionscript to compute the time anymore.
Is there a way to make the timer continue counting even if the movie jumps to different frames (sort of like a global function)?
I’m certain I’m overlooking a simple solution to this and any assistance will be much appreciated. Thanks!