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

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

New Here ,
Feb 07, 2018 Feb 07, 2018

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

Views

1.1K

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Amazing that works! Thanks so much!

Cheers,

Michael

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

super helpful thx!!!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

or just on 254

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Yes, my mistake

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Whoa! Excellent!

Gotta bookmark this. Haha

Votes

Translate

Translate

Report

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