Skip to main content
Participant
June 9, 2016
Question

Loop Animate CC timeline X times and stop

  • June 9, 2016
  • 1 reply
  • 30852 views

I'm trying to loop the timeline a few times and stop. All the help files I have found so far do not work. Anyone have any ideas?

This topic has been closed for replies.

1 reply

Inspiring
June 9, 2016

Another time, try to search forum

Put this code on last frame. This is sample for 3 loops.

if(!this.alreadyExecuted){

this.alreadyExecuted=true;

this.loopNum=1;

} else {

this.loopNum++;

if(this.loopNum==3){

this.stop();

}

}

Legend
June 9, 2016

You can do it in a lot less code than that:

  1. if (!this.looped) this.looped = 1
  2. if (this.looped++ > 3) this.stop(); 

Put the code wherever you want it to stop, set the 3 to the desired loops.

Strange how often this specific simple question comes up.

just.emma
Inspiring
June 9, 2016

I mentioned this in another thread with the same subject but I'll add it here as well... that code is more concise but I would change it to:

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

if (this.looped++ == 3) this.stop();

(== instead of >) so that it stops at exactly at a specific number of loops.  Your example loops 4 times instead of 3.