# Crazy delay when using setInterval more than once?

**URL:** <https://forum.kirupa.com/t/crazy-delay-when-using-setinterval-more-than-once/130309>\
**Category:** Uncategorized\
**Created:** [December 3, 2004, 11:30am UTC](https://forum.kirupa.com/t/crazy-delay-when-using-setinterval-more-than-once/130309 "2004-12-03T11:30:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![darthmahon](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@darthmahon](https://forum.kirupa.com/u/darthmahon)\
**Post date:** [December 3, 2004, 11:30am UTC](https://forum.kirupa.com/t/crazy-delay-when-using-setinterval-more-than-once/130309/1 "2004-12-03T11:30:29Z")

</div>

Ok I am having some major headaches with time delays. Basically, I have the following function to delay a frame, then go to the next:

[AS]  
// Delay next frame  
function unpause() {  
gotoAndStop(\_currentframe+1);  
clearInterval(my\_interval);  
}  
[/AS]

So I have 3 frames - on frame 1 I have:

[AS]  
// resize mask  
mc\_maincontent.resize(485, 280, 6);

// delay playing of next frame  
my\_interval = setInterval(unpause,1000);  
stop();  
[/AS]

on frame 2 I have:

[AS]  
// fade out white  
mc\_white.\_alpha = 100;  
mc\_white.fadeout(0, 10);

// show ring  
mc\_ring1.\_x = 200;  
mc\_ring1.\_y = 500;  
mc\_ring1.pos(200, 350, 60);

// delay playing of next frame  
my\_interval = setInterval(unpause,2000);  
stop();  
[/AS]

on frame 3 I have:

[AS]  
mc\_ring1text.fade(100, 10);  
stop();  
[/AS]

Basically I have split my movie into different frames - so I can run specific functions to aid my animation. This is all in a movie called “gallery.swf”. Now, I have a button on another movie that loads “gallery.swf” into \_level3 as so:

[AS]  
on (release) {  
loadMovie(“gallery.swf”, 3);  
}  
[/AS]

Now as I said, the first time I click this it is ok - however, it I then click it quickly in sucession like a madman or click on another menu item which loads a different movie into \_level3 before my “gallery.swf” movie has finished playing, everything goes mental - things loop and nothing is timed as it should be - I am using the delay function in all of my swf movies - is it because I am calling the same function many times?

Do I need a clearInterval(my\_interval); to be run on the button so it clears anything leftover?

This is really halting my plans on this movie, any ideas?

Cheers,  
Chris
