PDA

View Full Version : Stopping a function from a dynamicly loaded mc



Meridian
July 22nd, 2003, 11:52 PM
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.


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);


I've tried variations of

delete _root.setinterval(movieDelay,10000)

_root.setinterval(movieDelay, 10000)

nothing seems to be stopping this monster..

claudio
July 23rd, 2003, 12:22 AM
function movieDelay() {
count = Math.floor(Math.random()*3)+1;
feature.loadMovie("movies/featured"+count+".swf");
}
delayInterval = setInterval(movieDelay, 1000);
And on your button set:on (press) {
clearInterval(delayInterval);
}

Meridian
July 23rd, 2003, 12:47 AM
Wow, thanks that new code is sexy.. :)

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..

claudio
July 23rd, 2003, 12:51 AM
You can useon (press) {
delayInterval = setInterval(movieDelay, 1000);
}

Meridian
July 23rd, 2003, 12:55 AM
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..

claudio
July 23rd, 2003, 01:01 AM
I dont get it... And it should bedelayInterval = setInterval(_root.timer.movieDelay, 1000);

Meridian
July 23rd, 2003, 01:04 AM
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.

claudio
July 23rd, 2003, 01:06 AM
You're welcome =)

kode
July 23rd, 2003, 01:31 AM
Since the variable count is not used anymore, use a local variable.
function movieDelay() {
var count = Math.floor(Math.random()*3)+1;
feature.loadMovie("movies/featured"+count+".swf");
}
That way it will be destroyed after the function has been executed. ;)

claudio
July 23rd, 2003, 01:42 AM
Good point Kax.... :sure: