6 Replies Latest reply on Jun 26, 2007 5:02 AM by Sketchsta

    clearInterval()

    Sketchsta Level 1
      I have a few slides in separate .swf files which im loading one at a time, using loadMovie()
      these slides are using setInterval() to pause for 4 seconds before moving to the next pic.

      //*** CODE:
      stop();
      pausePic = setInterval ( this, "nextFrame", 4000 );

      //*** CODE on the following frame:
      clearInterval (pausePic);
      play();

      this works with no problems when i load each one..
      The problem comes when i'm unloading the swf. I thought by unloading the movie, it automatically clears all Intervals. But thats not the case. When i load the same slide swf again, these things happen randomly...

      *start to play for a few frames, then stop.
      *start playing, but the pausePic intervals are reduced in time. The more times i load the quicker the intervals are.
      *not play at all
      *start to play, but 1 frame at a time... almost 1 to 2 frames per second

      My question is, How do I clear each Interval on unloadMovie() ?

      I tried to have a clearInterval(pausePic); at the beginning of each slide.swf, and also tried to clearInterval() from the unloadMovie() function, but that doesn't work either.

      Any Ideas what might be happening?

      Thanx in advance.
        • 1. Re: clearInterval()
          Greg Dove Level 4
          How are you trying to use clearInterval before the unLoadMovie command?

          If you are doing it from code in the timeline that contains your loaded movie, are you doing it like this?

          clearInterval(myMovieClip_mc.pausePic)
          unloadMovie(myMovieClip_mc)
          • 2. Re: clearInterval()
            tusharwadekar
            Yes, It's pretty weird. I too have faced same issues earlier. What happens is, even though the movie is unloaded, the interval object is not. You will have to make sure that you clear all the intervals in that movie before unloading it.
            • 3. Re: clearInterval()
              Sketchsta Level 1
              GWD, yes thats how i tried, but still no good.

              what im actually doing here is, im using a for() loop to unload all movies, then load a specific one which corresponds to a button.


              //**** unload function
              function unloadS(){
              for(var l=1; l<=6; l++){
              unloadMovie(eval("_root.slide"+l));
              }
              }

              could this have some sort of effect on it?


              tusharwadekar,
              i dont know how else to clear the intervals. I already tried clearInterval() before loadMovie() that didnt work...

              You said you too have gone through this... how did you solve it?
              • 4. Re: clearInterval()
                Greg Dove Level 4
                OK... well that's how I'd try to remove the setInterval...

                Only other thing I can suggest is to consider the difference between unLoadMovie an removeMovieClip.

                I tend to use them as MovieClip methods, rather than the global function approach... and I use MovieClip.removeMovieClip() rather than MovieClip.unloadMovie() because unloadMovie leaves the properties and clip handlers intact.

                I don't know if the same is true for the global functions, but its reasonable to assume so I guess (for the sake of consistency - I could not see this confirmed in the livedocs).
                I still don't think that will solve the problem though... I don't think the interval is associated with the clip, just the pausePic property which allows us to reference that specific interval when using clearInterval ( if I understand things correctly... which I may not). Others may know more....Let's hope so.
                • 5. Re: clearInterval()
                  tusharwadekar Level 1
                  I used onClipEvent to clear interval before movie jumps to next frame.

                  onClipEvent(unload){
                  clearInterval(myInterval);
                  }

                  My scenario was like this:
                  1) There were many components on the timeline. Each one was having it's own interval.
                  2) Depending on some interaction, user was able to move further (nextFrame)
                  3) I used onClipEvent(unload) to clear the interval. Thus just before moving to next frame, the interval of current component was cleared.

                  Here is a working example:

                  1) Create a MovieClip named mc on first frame.
                  2) In that movie clip, add below mentioned code.
                  function callback(mc){
                  trace(mc);
                  }
                  var myInterval = setInterval(callback, 1000, this);
                  3) Exit edit mode and add below mentioned code on the same movie clip:
                  onClipEvent(unload){
                  clearInterval(myInterval);
                  }
                  4) Insert one frame on main timeline. make sure that the instance of movie clip is not available on second frame.
                  5) Now add a button on first frame clicking which main movie will jump to second frame
                  6) Test the movie. It should work as expected. Traces will not appear once you go to second frame.
                  7) If you remove unload code, even if movie is on second frame traces will continue to appear. however the value of this would be undefined!

                  Hope this helps!
                  • 6. Re: clearInterval()
                    Sketchsta Level 1
                    GWD,
                    I tried, just out of curiosity mainly, to use removeMovieClip() but you were right, it didnt work unfortunately.
                    Good to have a different point of approach tho, i'll have to remember that when next i stick to habbit. =)

                    Tushar, I used your onClipEvent(unload) tactic, and that did the trick. It works good now. Thanx alot foe that.

                    I'm still however wondering why clearInterval() didnt work from a button click tho...

                    ohh well... if anyone reads this post and can point that out, that would be great.
                    But for now... it works fine.

                    thanx for the help guys, much appreciated.