Skip to main content
TDSwift
Participant
November 16, 2016
Answered

Animate CC Loop

  • November 16, 2016
  • 4 replies
  • 1461 views

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();

}

    This topic has been closed for replies.
    Correct answer TDSwift

    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.

    4 replies

    TDSwift
    TDSwiftAuthorCorrect answer
    Participant
    November 16, 2016

    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.

    rezun8
    Inspiring
    November 16, 2016

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

    Cheers

    rezun8
    Inspiring
    November 16, 2016

    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();

    }

    }

    Legend
    November 16, 2016

    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();

    Legend
    November 16, 2016

    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.