Skip to main content
Participant
April 14, 2021
Answered

Loop timeline, then stop on a specific frame in final loop — not stopping nested movie clips

  • April 14, 2021
  • 2 replies
  • 1229 views

Hello!

 

New to Animate, very new to JS. I've built a banner ad in the HTML5 Canvas, but I feel like I'm missing something obvious. Based on this thread, I applied the following code to the frame where I'd like my animation to stop after looping:* 

 

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

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

 

I applied the action at the top level of my .fla (I have several nested movie clips and would like all to stop on a specific frame). For a while I thought it wasn't working at all, but now I see that the stop action is only effecting my background layer (not any of the other movieclips). Can anyone help me understand how to get EVERYTHING to stop simultaneously? (see image below)

 

*I would actually like to loop the animation 3 times and have it stop specifcally on frame 231 of 240, if that information is useful. I just figured I'd try the code above to start

 

 

 

This topic has been closed for replies.
Correct answer kglad

OK, I think follow what you're saying. That still didn't work, but I think I understand why: It's because my movieclips technically *aren't* on frame 231 of the main timline (right?). Those movieclips only appear on frame 1 of the main timeline (everything else on the main timeline is just frames)*, so I need to go into each movieclip and insert the code snippet where I want each of those animations to stop. Is that correct?

 

For example, a movieclip that is on the "background" layer (motorcycleBG_mc) contains three additional movieclips for the animating circles. To get these to stop, I had to paste your original code snippet within the "motorcycleBG_mc" movieclip

 

*It's also entirely possibly that I built this whole ad not using best practices. Still learning!

 


no, any movieclip created on frame 1 (or whenever), that still exists on frame 231, can be referenced by the instance name assigned on the frame where it was created.

 

otoh, if the movieclip is tweened after creation, that can changed its instance name.

 

and further, i don't see a downside to using @JoãoCésar17023019's suggestion:

 

if(!this.looped){

this.looped=1;

} else {

this.looped++;

if(this.looped==3){

this.framerate = 0;

}

}

2 replies

JoãoCésar17023019
Community Expert
Community Expert
April 15, 2021

Hi.

 

To stop a Movie Clip instance and all of its chidren, set the framerate property to 0. Like this:

this.yourMC.framerate = 0;

 

Regards,

JC

Participant
April 16, 2021

This worked when combined with @kglad's suggestions above. Thanks so much!

JoãoCésar17023019
Community Expert
Community Expert
April 16, 2021

You're welcome!

kglad
Community Expert
Community Expert
April 15, 2021

on frame 231, use:

 

if(!this.looped){

this.looped=1;

} else {

this.looped++;

if(this.looped==3){

this.stop();

}

}

 

(which can be compressed to the code you showed, but it's, imo, foolish to do so.)

Participant
April 15, 2021

Thanks for the help! But alas — I applied this code, and got the same results. The only thing that stopped was the background layer. (see screencap here)

 

I had been looking into this thread and wondered if I needed to specifically add a stop for each movie clip instance (which seems tedious and like it's probably not necessary, but what do I know). Thoughts?

kglad
Community Expert
Community Expert
April 15, 2021

that will stop the timeline that it's added to.  if that code is on frame 231 of the main timeline and there are movieclips on frame 231 of the main timeline, they need to be stopped too.  ie, if there are movieclips mc1 and mc2 on the main timeline where you want everything to stop use:

 

if(!this.looped){

this.looped=1;

} else {

this.looped++;

if(this.looped==3){

this.stop();

this.mc1.stop();

this.mc2.stop();

}

}