I have a function to make a number count up tp sixty. I want it so if you leave the frame the counter will reinitiate on return. As it is, the counter works fine the first time through, but runs faster everytime you return to frame. Here is the code.
textValue = 10;
addValue = 1;
txt_ET.text = textValue;
function countUp(){
clearInterval(Interval);
if (textValue < 60){
clearInterval(Interval);
textValue += addValue;
txt_ET.text = textValue;
}
}
setInterval(countUp,800);
You should look in the help documentation regarding the use of setInterval and clearInterval to learn how they work.
If you want to clear an interval you need something to identify the interval. When the setInterval function executes, it returns a Number value that is such an identifier. You use that number in the clearInterval function call. So for what you show above, your setInveral line should look something like...
var Interval:Number = setInterval(countUp, 800);
then your clearInterval function call as shown should work... except you have a redundant calling of it within the function... one of the two shown is unnecessary - I would guess the first...
function countUp(){
clearInterval(Interval);
if (textValue < 60){
clearInterval(Interval);
I guess I should explain the project i'm editing. I am editing an Actionscript 2 project that is screen based. I have this code in a movie clip. Inside this movie is a text object that I want to be at ten and count up to 60. I also have a button so the viewer can advance to the next screen if He doesn't want to wait for the number to get to 60. The problem is that if the viewer hits the "NEXT" button and goes to the next screen and then decides to go back I want the counter to reset to 10. Currently, it runs great the first time through, but if you advance to next screen early and come back the counter keeps going where it left off. It doesn't reset.
North America
Europe, Middle East and Africa
Asia Pacific