Skip to main content
HannaB
Inspiring
October 17, 2019
解決済み

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

  • October 17, 2019
  • 返信数 1.
  • 6484 ビュー

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?

このトピックへの返信は締め切られました。
解決に役立った回答 avid_body16B8
Oh, and I had to put back the ' ' around the frame numbers or it wouldn't work at all.
try this: https://app.box.com/s/2ajf86jgmbms81dqykkc5uqviur6zip5

返信数 1

Legend
October 17, 2019

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?

HannaB
HannaB作成者
Inspiring
October 17, 2019
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?
Legend
October 17, 2019

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.