Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help! How can I exit loop after looping certain times?

New Here ,
Feb 07, 2018 Feb 07, 2018

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

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2018 Feb 07, 2018

Amazing that works! Thanks so much!

Cheers,

Michael

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 20, 2018 Mar 20, 2018
LATEST

super helpful thx!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 07, 2018 Feb 07, 2018

or just on 254

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

if (this.looped++ == 3) this.gotoAndStop(255);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2018 Feb 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 07, 2018 Feb 07, 2018

Yes, my mistake

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2018 Feb 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

Whoa! Excellent!

Gotta bookmark this. Haha

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines