1 Reply Latest reply on Jul 8, 2011 10:52 AM by Ned Murphy

    Looping a movie clip a specific number of times in Flash

    SabelV Level 1

      Does anyone know how to get a movie clip to loop a specific number of times in Flash? I know how to stop a movie clip from looping by using the this.stop (); command by placing the command in a separate Action Script layer, in a keyframe, inside of the movie clip's timeline. This allows the movie clip to play through once and then stop. But I need for the movie clip to loop more than once, maybe 2 or 3 times, and then go back to the main timeline. Does anyone know the code for this?

       

      Also, is it possible to place a pause (I'm guessing, maybe by using a timer of some type?) between the loops, so that the movie will pause a couple of seconds before it loops again and then stop? Please note I do not need the movie clip to stop when there's an event like a rollover or anything. I just need it to play a couple of times, pause between plays and then stop and go back to the main timeline. Please let me know if anyone can help.

       

      Thanks,

       

      Sarah

       

      P.S. Is there a good, easy to use, reference book anyone can recommend for creating specific things in Flash using Action Script? Do you guys have a favorite for beginners like me?

        • 1. Re: Looping a movie clip a specific number of times in Flash
          Ned Murphy Adobe Community Professional & MVP

          You can use a variable to keep count of how many times you loop, and until it exceeds a particulr value (2 or 3) you execute a setTimeout() call that waits for however long you want to delay and then tells the movieclip to gotoAndPlay(1).

           

          So in the first frame you would establish the counting variable...

           

          var count;

           

          if(count == undefined){ // only set it to 0 once
          count = 0;
          }

           

          and in the last frame you would do your incrementing and control....

           

          stop();

           

          count += 1;

           

          if(count < 3){
          setTimeout(waitABit, 2000); // call function in 2 secs
          }

           

          function waitABit(){
          gotoAndPlay(1);
          }