4 Replies Latest reply on Feb 20, 2011 4:19 AM by Ned Murphy

    Stop Looping Codes

    jess-scene

      When creating a moving flash banner, it will continuously loop.

      Is it respectful for the viewer to only loop it a certian amount of times or does that even matter?

      If so, where could I find the code to accomplish that AND stop it at a certain frame?

       

      THANK!!

        • 1. Re: Stop Looping Codes
          Ned Murphy Adobe Community Professional & MVP

          It's anybody's call how many times something should loop.  It's sometimes something that is better decided after allowing it to loop continuously for awhile to get feedback/reaction.

           

          To accomplish it, you basically need to keep a count of the number of loops and then use a conditional code to tell the timeline to stop();  This would normally be something like the following that you would place in the frame where you want it to stop.... numLoops and someLimit are homegrown variables...

           

          if(numLoops == someLimit){

               stop();

          } else {

               numLoops += 1;

          }

          1 person found this helpful
          • 2. Re: Stop Looping Codes
            dementedsugar Level 1

            I declared

             

            var numLoops = 0;

            var sumLimit = 2;

             

            in the first frame,

             

            then put

             

            if(numLoops == sumLimit){
                 stop();
            } else {
                 numLoops += 1;
            }

             

            on the frame I wanted it to stop. But it continues to loop over and over. What am I doing wrong?

            • 3. Re: Stop Looping Codes
              somascope Level 3

              Your issue is that every time you restart your loop, you are re-initializing your variables. In other words, when the loop goes back to, say, frame 1, "var numLoops = 0" is always resetting things to 0.

               

              A simple fix is to loop to a frame AFTER wherever your vars are being set (like, gotoAndPlay(2), as a simple example). That way, the playhead never passes over them a 2nd time, and avoids them getting reset.

              • 4. Re: Stop Looping Codes
                Ned Murphy Adobe Community Professional & MVP

                Don't assign a value in the first frame, just declare it.  The default value will be a zero, but upon returning it will not reset...

                 

                var numLoops:int;

                var sumLimit = 2;