Skip to main content
Participant
January 12, 2021
Question

Loop timeline then play frame label

  • January 12, 2021
  • 1 reply
  • 282 views

Hello Everyone,

 

This is my first post and I'm not really a programer so please go easy on me. I'm trying to loop my timline from frame 1 to frame 253 and then once it has reached two loops it goes to and plays a Frame Label. The code below is what I've placed at frame 253 and it loops but it just loops continuosly once it hits frame 253. Can anyone sugest an edit to get this snippet to work correctly? Thanks very much!

 

this.loopsPlayed++; console.log(this.loopsPlayed);
 
if (this.loopsPlayed >= 2) {
this.gotoAndPlay('_end');
} else {
this.gotoAndPlay(0);
}

 

 

This topic has been closed for replies.

1 reply

Joseph Labrecque
Community Expert
Community Expert
January 13, 2021

If you assign your loopsPlayed to a value of 0 or whatever in a previous keyframe (0?) - be SURE that the playhead never hits that frame again or else it'll reset the value to 0 each time. 

Participant
January 13, 2021

Thanks Joseph! I wasn't sure where my script was wrong. I used a script from another banner and modified it to use frame labels instead of frame numbers. It works now! Loops twice and then plays my end animation. Thanks for your help! BTW, I've been watching your tutorials for a long time, big fan!

 

if (!this.looped) this.looped = 1;
if (this.looped++ == 2) this.gotoAndPlay('_end');
else {
this.gotoAndPlay('_start');
}