setInterval

Hey,

I have a movie with the main content loaded on _level1. In this movie I have a function:
[AS]intervalID = setInterval(advPhoto, 2000);[/AS]
when I load a different movie into that level then load the previous one again, the function is still triggered. If I trigger the fuction again it just doubles up and I can only stop the second instance.

I would’ve though that unloading the movie would kill the setInterval on this level.

I have tried to clearInterval(intervalID) when the movie loads.

Any Ideas?

Would you post the whole code? :slight_smile:

sure…
[AS]hiddenButton.onRelease = function() {
buttonswitch();
};
buttonState = false;
function buttonSwitch() {
if (buttonState == false) {
intervalID = setInterval(advPhoto, 2000);
buttonAnim.gotoAndStop(2);
buttonState = true;
} else {
clearInterval(intervalID);
buttonAnim.gotoAndStop(1);
buttonState = false;
}
}
function advPhoto() {
changePhoto(1);
}
[/AS]

Well, the code seems to be fine. Which means that (kind of obvious (but I didn’t know!)) the interval is not cleared. Can’t you just clear the interval before you load the new movie?

i did try that…

[AS]on (release) {
loadMovie(“gallery.swf”, 1);
_level1.clearInterval(intervalID);
}
[/AS]

This code is on the button that loads the movie to level1

but to no avail…

wierd.

Try to clear the interval before you call the loadMovie method.
[AS]on (release) {
_level1.clearInterval(intervalID);
loadMovie(“gallery.swf”, 1);
}[/AS]
I’m not sure though… :-\

yeah, I tried that too…

no luck

Ha… Is this frustrating you as well yet?

Ehmm… Yes!

Could you attach the FLA?

i have put up a quick example here

http://www.in2corp.com/ftp/SetIntDramas.zip

Ok… I think you zipped the wrong test1.fla and test2.fla files… :crazy:

Anyway, try using this little function, it will clear every interval in the Flash movie.
[AS]_global.clearAllIntervals = function() {
var i = 0, n = setInterval(arguments.callee, 10000);
while (i++<n) clearInterval(i);
};[/AS]
I repeat, it will clear them all.

Just call the function from anywhere in the movie.
[AS]clearAllIntervals();[/AS]

MAN THIS THING WILL NOT DIE!!!..

i have put it in the first frame of the loaded movie.
I have tried it on the button.

This is wierd.

i have updated the zip
http://www.in2corp.com/ftp/SetIntDramas.zip

I’m so stupid!! :stuck_out_tongue:
[AS]on (release) {
clearInterval(_level1.intervalID);
loadMovie(“test2.swf”, 1);
}[/AS]
…This is the second time tonight that I didn’t see the error. :-
I really should go to bed. :stuck_out_tongue:

YEAH.

thanks for helping me through the hell that is setInterval

appreciated.

Drew

Hehe - You’re welcome. :wink:

And now, I’m off to bed. :sleep: