5 Replies Latest reply on Nov 16, 2016 1:01 PM by TDSwift

    Animate CC Loop

    TDSwift

      I am trying to create a loop using the below:

      "loop" is a frame label 1 frame after the below on the main timeline.

      Can someone find what is keeping this from working?

      Thank you!

       

      var i = 0;

      i++;

      if (i < 2) {

      this.play("loop");

      } else if (i > 2) {

        this.stop();

      }

        • 1. Re: Animate CC Loop
          ClayUUID Adobe Community Professional

          You initialize i to zero every time you enter the frame.

           

          The variable i only exists in that frame.

           

          The conditional logic doesn't account for i being equal to 2.

           

          There's no such function as .play().

           

          There's no need to use a frame label when you're just advancing to the next frame.

          • 2. Re: Animate CC Loop
            rezun8 Level 4

            I use this in my banner ads to loop the creative 2x:

             

            if(!this.alreadyExecuted){

            this.alreadyExecuted=true;

            this.loopNum=1;

            } else {

            this.loopNum++;

            if(this.loopNum==2){

            this.stop();

            }

            }

            • 3. Re: Animate CC Loop
              ClayUUID Adobe Community Professional

              I don't know why people are still using that ungainly code when a perfectly functional two-liner has been posted here many times:

               

              if (!this.looped) this.looped = 1;

              if (this.looped++ > 2) this.stop();

              • 4. Re: Animate CC Loop
                rezun8 Level 4

                sorry clay it wasnt to your standards, I will use your updated code from now on.

                Cheers

                • 5. Re: Animate CC Loop
                  TDSwift Level 1

                  Thank you for the tips @ClayUUID. You got me on the right track. After making the adjustments you suggested, the loop works as expected.

                   

                  /*defined i=0 in first frame

                  placed this.gotoAndPlay("restart"); on last frame

                  placed "restart" label on first frame */

                   

                   

                  if (i < 3) {

                  i++;

                  } else if (i == 3) {

                    this.stop();

                  }

                   

                  ClayUUID  Nov 15, 2016 8:28 PM (in response to Tony Dilger)

                  ANSWER!

                  You initialize i to zero every time you enter the frame.

                  The variable i only exists in that frame.

                  The conditional logic doesn't account for i being equal to 2.

                  There's no such function as .play().

                  There's no need to use a frame label when you're just advancing to the next frame.