Copy link to clipboard
Copied
Hi guys,
I'm sorry if this question was asked before but I really couldn't find an answer to this:
How can I loop a banner from frame 1 to frame 255 three times and when it's playing the 4th time it should play until frame 256 which is the final frame.
Thanks a lot,
Michael
Copy link to clipboard
Copied
Hi.
Use this code:
Frame 1 (0):
if (this.resume >= 0)
this.resume++;
else
this.resume = 0;
Frame 255 (254):
if (this.resume < 3)
this.gotoAndPlay(0);
else
this.gotoAndStop(255);
Regards,
JC
Copy link to clipboard
Copied
Amazing that works! Thanks so much!
Cheers,
Michael
Copy link to clipboard
Copied
You're welcome!
Copy link to clipboard
Copied
super helpful thx!!!
Copy link to clipboard
Copied
or just on 254
if (!this.looped) this.looped = 1;
if (this.looped++ == 3) this.gotoAndStop(255);
Copy link to clipboard
Copied
That wouldn't send the timeline back to frame one. The fixed version would be:
if (!this.looped) this.looped = 1;
if (this.looped++ < 3) this.gotoAndPlay(1);
On the second-to-last frame, whatever it happens to be.
Copy link to clipboard
Copied
Yes, my mistake
Copy link to clipboard
Copied
I was curious whether this could be done as a one-liner. Turns out it can:
(this.looped = !this.looped ? 1 : ++this.looped) < 3 ? this.gotoAndPlay(1) : 0;
Or this abomination:
this[["play", "gotoAndPlay"][+((this.looped = !this.looped ? 1 : ++this.looped) < 3)]](1);
Seriously, nobody use that.
Copy link to clipboard
Copied
Whoa! Excellent!
Gotta bookmark this. Haha