all groups > flash actionscript > january 2007 >
You're in the

flash actionscript

group:

onUnload


onUnload jonnybennett
1/3/2007 11:02:53 PM
flash actionscript: Okay I have a m.c. with an instance name of 'dave'. Dave m.c. has a setInterval
that I want to clear when the m.c. is removed.

this.onUnload=function():Void{
clearInterval(fadeOutInterval);
clearInterval(zoomInterval);}

The above code works fine if dave m.c is removed. However I also want it to
work if dave m.c. is within another m.c. and the outer m.c. is removed. eg.

outerMc.outerMc.dave

but if you remove outerMc instead of dave the onUnload is not clearing the
setINterval. Any ideas? thanks J.
Re: onUnload kglad
1/3/2007 11:14:10 PM
Re: onUnload cinemaguy
1/3/2007 11:22:02 PM
Re: onUnload jonnybennett
1/3/2007 11:25:02 PM
Thanks for the reply and please bear with me as I am self taught, and not
really sure what you mean.

however if i have a mc1, with mc2 nested in mc1 and Dave nested in mc2...ie.

mc1.mc2.dave

and I remove mc1 from the stage,
that removes mc1, and its children (mc2 and dave), however for some reason it
isn't clearing the setInterval within dave?

I say it isn't clearing because when you reacttach mc1, and therefore reset
the Intervals within dave it is creating problems. I am sure the problems are
arrising because it isn't clearing the intervals properly.

Is there a global clearInterval, that will clear any interval that is set?
thanks J.
Re: onUnload jonnybennett
1/3/2007 11:30:57 PM
clearInterval();

Re: onUnload cinemaguy
1/3/2007 11:33:26 PM
Is there any reason why you cant wrap these in a function and then just call
the function when you need it?

function globalClear() {
clearInterval(fadeOutInterval);
clearInterval(zoomInterval);
}
Re: onUnload kglad
1/3/2007 11:38:59 PM
i was wrong. you can make the interval reference a child of dave
(mc1.mc2.dave.intervalNum=setInterval() ), but the interval itself is not a
child and removing dave only removes the reference and fails to clear the
interval.

however (for the op), the onUnload function will still execute as long as dave
is unloaded, whether it's a child or not. your intervals will clear if they
are correctly referenced.
Re: onUnload jonnybennett
1/4/2007 6:01:14 PM
Thanks Kglad. But when I removem.c. dave it is not always clearing the
Intervals.
The only simple resolution I can see is if there is a way to globally clear
any intervals that are running without an IntervalID.
For some reason the onUnoad function to clear the INtervals is not claring
them and I can not bear to look at this any longer. Is there no way of simply
globally clearing all running INtervals without a IntervalID? Anyone
please..... aaaaaaaahhh!!
Re: onUnload kglad
1/4/2007 6:35:25 PM
no, there's not clear all intervals function.

you can store all your intervals in an array (as they're created) and clear
them all by cycling through the array elements.

or you can use the correct path to your intervals in your onUnload() function.
AddThis Social Bookmark Button