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

At a loss — How do I get my animation to loop a set number of times before stopping?

Explorer ,
Oct 16, 2019 Oct 16, 2019

Copy link to clipboard

Copied

I'm a beginner. Sorry! But I've created an animation that works. It's simple and very straight forward.

 

But it doesn't do what I want which is to start when I click "Start" then loop three times and stop at the end of the animation at frame 58.

 

Here's what I have:

in Layer 1, frame 1 of the animation I have this:


var _this = this;
_this.stop();

 

In Layer 1, frame 2 and to the end (frame 58 is end) I have this:

 

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

if (this.looped++ > 3) this.gotoAndStop('58');

 

In Layer 2, frame 1 and to the end I have this (and a "Start" button):


var _this = this;
_this.button_2.on('click', function(){
_this.gotoAndPlay('2');
});

 

Animation starts when I click "Start" but it only plays once, then goes back to beginning and stops. It seems my "Stop" in Layer 1, frame 1 overrides the loop command? But what do I do to prevent the animation to auto play on load if I don't have a Stop action in there?

TOPICS
ActionScript , Code , How to , Timeline

Views

3.8K

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

correct answers 1 Correct answer

LEGEND , Oct 17, 2019 Oct 17, 2019

Votes

Translate

Translate
LEGEND ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

It sounds like you're creating a banner ad. But your code is AS3, which won't work in an HTML5 Canvas document, which is what you have to use for ads now.

 

Which is it?

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

HI, I'm creating a simple animation to be placed on a page on a website. Not a banner ad. So far I've gotten a little farther than above, but still not getting it right. For now, the video loops the number of times I like and then stops. BUT, as soon as I add in a "Stop" function, the looping won't work. I want the animation to start when I click "Start", not auto-play as soon as page loads. But I can't figure out where on the timeline to place the Stop without it interfering with the loop command. Can I send you a file somehow?

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

You seem to have ignored the part of my post where I said you can't use AS3 code. You can't use AS3 code. You have to use JavaScript. Look at the code hints for Canvas documents. Look at the browser developer console for errors when testing the page.

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Not ignoring anything — I'm just not very skilled in this or understand coding. I was hoping to get a piece of code to insert rather than a reference to hints and JavaScript. I am a little old lady who doesn't program...

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

I've revised my original post to include the actual code I've used. Would greatly appreciate help with this!

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Hey Hanna. Here is an example of how you could do it.

 

https://app.box.com/s/toxn0ixv2944r0yv5emuj6joh5smi60c

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Eagerly waiting to find out what solution you were going to show me 😉

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Why do you have your frame numbers in quotes? Did you create frame labels "58" and "2"?

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

I got the code from this forum and copied it and updated with my own frame numbers. I have not set labels. Don't know how to do 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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

To Resdesign — I'm not sure what to learn from the .fla file you sent me. It loops indefinitely for me. And it also doesn't have a start button so it auto plays. If you see my original post, I'm explaining my issue there. I'm a beginner here so please bear with me!

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

This is strange. It loops only 3 times for me and stops. Agreed about the frame number It should not be in quotes. Anyway, I was not trying to make the whole thing for you, only showing you a way to stop after playing 3 times. Please play it again. I added a visible counter for you to see. download it again. Code is in the movie clip. https://app.box.com/s/toxn0ixv2944r0yv5emuj6joh5smi60c

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

please press enter from ANCC to play in you default browser. there is no way this plays continually in any browser.

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Yup. Just keeps playing and playing when I do "Test" — maybe I'm using the wrong way to test it? And the counter just says "counter" and doesn't show any numbers per loop. I stopped counting at 6th loop. Weird!

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

you must be doing it wrong. from ANCC, press ctrl-enter or cmd-enter. It should open your browser.

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Same result. It plays and plays. But did you look at my original issue? I can get my animation to loop the number of times I want but I need a Stop action in the beginning so it doesn't auto-start. Where do I put that "Stop" action so it doesn't interfere with the loop once started? Can I send it to you? How?

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

That's insane! I tried it on multiple browser and this is the correct way to do it.

If it is a video, then in the component parameters check off autoplay.

video no autoplay.png

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

I uploaded my animation in case you can take a look at it. Maybe it works for you since nothing works for me when it should... https://app.box.com/s/rbl4unpj76yp8gznfthkj6w6dpy4bkjj

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

I'm using Adobe Animate, if that makes a difference. Not doing anything other than opening your file in Animate and then Cmd + Return.

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Oh, and I had to put back the ' ' around the frame numbers or it wouldn't work at all.

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

That is almost perfect! Only thing now is that when it's done its loops and you restart, it only runs once but I want it to restart the looping. Question, to make it loop 5 times instead, do I change the "if(i<4){" in frame 59 to "if(i<6){" instead?

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

yes. 5 is less than 6. You will have to reset i to 0 for it to start again.

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
Explorer ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Any chance you can tell me how to do that or should I wing it to reset "something" to 0?

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 ,
Oct 17, 2019 Oct 17, 2019

Copy link to clipboard

Copied

Change the code to:

 

i++;

if(i<6){
	this.gotoAndPlay(2);
} else{
	this.gotoAndStop(0);
	
}

 

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