5 Replies Latest reply on Apr 18, 2007 12:40 AM by Greg Dove

    Flash 8 crashed due to simple AS...?

    ibrubru
      I have created a keyframe with a static graphic and the next keyframe that has a movie clip that runs for 5 secs.

      Actionscript on the first keyframe (33):

      stop();
      countDown = function(){
      gotoAndStop(34);
      }
      timer = setInterval(countDown, 5000);


      AS on 2nd keyframe (34):

      stop();
      countDown1 = function(){
      gotoAndStop(33);
      }
      timer1 = setInterval(countDown1, 5000);


      What I'm trying to do is to have the movie show frame 33 for 5 seconds then goto frame 34 for another 5 seconds.
      I'd like it to loop every 10 seconds forever but it crashes the program on the 3nd or 4th run.
      any ideas? thanks in advance.

      bru
        • 1. Re: Flash 8 crashed due to simple AS...?
          Greg Dove Level 4
          You should use clearInterval as follows, otherwise its trying to call the functions every 5 seconds no matter where it is.:

          stop();
          countDown = function(){
          clearInterval(timer);
          gotoAndStop(34);
          }
          timer = setInterval(countDown, 5000);

          and

          stop();
          countDown1 = function(){
          clearInterval(timer1)
          gotoAndStop(33);
          }
          timer1 = setInterval(countDown1, 5000);


          • 2. Re: Flash 8 crashed due to simple AS...?
            Greg Dove Level 4
            There is another function that was undocumented in the original Flash 8 docs

            setTimeout

            which works similar to setInterval, but is only called once after a delay.
            You could use that instead (in a way it would make more sense).... but it doesn't really make any difference, because you should use the clearInterval or clearTimeout functions for both (clearInterval stops a setInterval, but they both clean up memory use associated with the timed call) and in the end here you have the same result.
            • 3. Re: Flash 8 crashed due to simple AS...?
              ibrubru Level 1
              amazing GWD, you saved my day. Thank you so much !!!
              • 4. Re: Flash 8 crashed due to simple AS...?
                ibrubru Level 1
                setTimeout sounds like Javascript. I should definitely check it out.
                just curious, is there a simplier way of achieving what I'm trying to do here? (maybe shorter code ...?)

                thanks again for your prompt response and help.

                quote:

                Originally posted by: GWD
                There is another function that was undocumented in the original Flash 8 docs

                setTimeout

                which works similar to setInterval, but is only called once after a delay.
                You could use that instead (in a way it would make more sense).... but it doesn't really make any difference, because you should use the clearInterval or clearTimeout functions for both (clearInterval stops a setInterval, but they both clean up memory use associated with the timed call) and in the end here you have the same result.


                • 5. Re: Flash 8 crashed due to simple AS...?
                  Greg Dove Level 4
                  you're welcome. There's probably other ways to do it, as with most things, but I think the way you're doing it is fine. I also wouldn't consider myself an expert on what is the optimal approach. I'm constantly surprised to find simpler ways to do things that have become my 'habits'. A lot of the time its from other threads in these forums.

                  I believe setTimeout is very similar to the javascript version...

                  Check out the comments at the very bottom of this page:
                  http://livedocs.adobe.com/flash/8/main/00001766.html#wp145915