Stopping a function from a dynamicly loaded mc

Hi there…

I’m using a timer on a keyframe to auto refresh mcs every 10 secs. This is working correctly but when I click on a button from a dynamically loaded mc I want it to stop the function from running.

[AS]
function movieDelay() {
choice = Math.round(Math.random()*2);
switch (choice) {
case 0 :
feature.loadMovie(“movies/featured1.swf”);
break;
case 1 :
feature.loadMovie(“movies/featured2.swf”);
break;
case 2 :
feature.loadMovie(“movies/featured3.swf”);
break;
}
}
setInterval(movieDelay, 10000);
[/AS]

I’ve tried variations of

delete _root.setinterval(movieDelay,10000)

_root.setinterval(movieDelay, 10000)

nothing seems to be stopping this monster…

[AS]function movieDelay() {
count = Math.floor(Math.random()*3)+1;
feature.loadMovie(“movies/featured”+count+".swf");
}
delayInterval = setInterval(movieDelay, 1000);[/AS]
And on your button set:[AS]on (press) {
clearInterval(delayInterval);
}[/AS]

Wow, thanks that new code is sexy… :slight_smile:

New question

How do I restart that bad dog?

Should I

A- try delteting and duplicating the mc with the code

or

B- use the setinterval again?

I tried


setInterval(_root.timer.delayInterval);

but that didn’t worky for restarting it. Where as it did for stoping it.

doh…

You can use[AS]on (press) {
delayInterval = setInterval(movieDelay, 1000);
}[/AS]

That would normally work, but since the mc that is restarting the interval is dynamically loaded it’s having issues.

I thought I’d be smart and use a direct path


_root.timer.delayInterval = setInterval(movieDelay, 1000);

but it doesn’t respond…

I dont get it… And it should be[AS]delayInterval = setInterval(_root.timer.movieDelay, 1000);[/AS]

No, you got it… That fixed it. heh I added the _root.timer path to everything except the movieDelay part of that code…

Thanks so much for your help.

You’re welcome =)

Since the variable count is not used anymore, use a local variable.
[AS]function movieDelay() {
var count = Math.floor(Math.random()*3)+1;
feature.loadMovie(“movies/featured”+count+".swf");
}[/AS]
That way it will be destroyed after the function has been executed. :wink:

Good point Kax… :sure: