8 Replies Latest reply on Jan 4, 2007 10:35 AM by kglad

    onUnload

    jonnybennett Level 1
      Okay I have a m.c. called '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.
        • 1. Re: onUnload
          kglad Adobe Community Professional & MVP
          why don't you make the interval a "child" of dave. then when dave is removed all intervals that are children of dave will be removed.
          • 2. Re: onUnload
            cinemaguy Level 1
            kglad for the sake of my own curiosity what do you mean by "make a child of dave"?
            • 3. Re: onUnload
              jonnybennett Level 1
              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.
              • 4. Re: onUnload
                jonnybennett Level 1
                clearInterval();

                is that a global clearInterval? it appears to be doing something.
                • 5. Re: onUnload
                  cinemaguy Level 1
                  Is there any reason why you cant wrap these in a function and then just call the function when you need it?
                  • 6. Re: onUnload
                    kglad Adobe Community Professional & MVP
                    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.
                    • 7. Re: onUnload
                      jonnybennett Level 1
                      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!!
                      • 8. Re: onUnload
                        kglad Adobe Community Professional & MVP
                        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.