-
clearInterval : Reset Clear all variables
Hello,
The setInterval works fine. So does the clearInterval. However, I'm trying to create a RESET button that simply reloads the swf (to restate my movie from the beginning). What happens is that the movie never really clears any variable like getTimer etc. The new movie retains all the old values/varibles. Even if I reset all variables to 0 or null, the newly reloaded movie retains the previous values it had before closing.
How do I truly clear all variables using clearInterval?
Thanks in advance.
iastini
mypause = setInterval(ftimer,1);
btn1.onPress = function(){//stop
clearInterval(mypause);
}
btn2.onPress = function(){//quit
fscommand("Quit");
}
btn3.onPress = function(){//reset
clearInterval(mypause);
mypause2 = setInterval(ftimer,1);
loadMovie("timer_motivate.swf", "_level0");
}
-
http://pat.theorigin.net
The easiest way to do this is to create an array that keeps track of all of the setintervals you create. Then make a function that runs through the array and clears them all.
-
http://pat.theorigin.net
Sorry, I totally missed this one. ClearInterval will ONLY clear a timer. If you want to reset your variables, you need to expressly set them to a new value.
In your script above, it looks like clearInterval is being used out of scope in reference to mypause. that line should read:
clearinterval(_root.mypause);
then in that same function you create a new timer mypause2. It will be rather impossible to clear mypause2 because you are declaring the variable reference within the function. Declaring a variable means that only that function has access to it. You should declare the variable outside the function:
var mypause2;
then you can use it within a function and have access to it in other functions as well.
-
Thanks guys, this sounds like a plan.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|