Skip to main content
Participant
June 3, 2006
Question

clearInterval

  • June 3, 2006
  • 4 replies
  • 355 views
I have a website that has several pages on it that are accessible through a nav bar at the top of the site. On the home page there is a continuous playing slideshow in a movieclip. when I go to another page and then back to the homepage the slideshow doesn't work sometimes, or other times it will play one of the images multiple times, and other times will skip images.

I have the slideshow running on an interval, and have tried using clearInterval to reset the slideshow when clicking off of the main page, so that upon returning to it, it will start again. I must be missing something to either clear the interval when going to another page or make the slideshow start over again when going back to the home page.

Any ideas?

thanks!
This topic has been closed for replies.

4 replies

alrazzleAuthor
Participant
September 30, 2006
Sorry I took so long to come back to this. School started up and I gave up on the project for a while.

Below is my code. I must be doing the clearInterval() incorrectly

var nInterval:Number;
var fadeIn:Boolean = true;

this.image1._alpha = 0;

fadeIn = true;
play();
nInterval = setInterval(fadeImage, 50, this.image1);

function fadeImage(mcImage:MovieClip):Void {
if(fadeIn) {
mcImage._alpha += 4;
if (mcImage._alpha >= 100) {
fadeIn = !fadeIn;
}
} else {
mcImage._alpha -= 4;
if (mcImage._alpha <= 0) {
fadeIn = !fadeIn;
clearInterval(nInterval);
}
}
updateAfterEvent();
};
kglad
Community Expert
Community Expert
September 30, 2006
your code looks ok as long as it's not attached to a frame that executes more than once while a loop is initiated. to prevent that problem use clearInterval just prior to setInterval():

kglad
Community Expert
Community Expert
June 6, 2006
there's no need to store all the intervals in an array and then clear them all prior to the declaration of all new setInterval() statements. simply execute clearInterval() just prior to all setInterval() statements, using the interval id of the about to be created interval.
Participant
June 5, 2006
One way that can solve your problem is saving your intervalID in an array. and when you do want to clear de interval, you clear the all array with de intervalID's.

That can solve problems when you create an intervalID,and then create another intervalID without clearing the first one. (This happens when an aplication is processing and its creates an intervalID before deleting the previous one, for example)

Maybe it can solve your problem!
kglad
Community Expert
Community Expert
June 4, 2006
what timeline contains your setInterval() statement, what timeline contains your clearInterval() statement and what are your setInterval() and clearInterval() statments?