Skip to content

Instantly share code, notes, and snippets.

@robbiegod
Last active October 9, 2020 19:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbiegod/997497d99d1923906989 to your computer and use it in GitHub Desktop.
Save robbiegod/997497d99d1923906989 to your computer and use it in GitHub Desktop.
Flash CC Pro HTML5 Canvas Loop Twice and then stop on the last frame

Flash CC Professional

HTML5 Canvas Animation that will play twice and then stop on the last frame.

Add a new layer called "actions". Insert a keyframe at the very beginning of your animation and then insert other keyframe at the very end.

Code for Frame 1
if(!this.loopsPlayed) {
	this.loopsPlayed = 0;
}
Code for the Last Frame
this.loopsPlayed++; console.log(this.loopsPlayed);

if (this.loopsPlayed >= 2) {
	this.stop();	
} else {
	this.gotoAndPlay(0);
}

If you want to have the animation play 3 times just change the "2" to a "3".

That's it. :)

FIN

@rome7777
Copy link

It worked great for me, but what if I want it to loop infinitely until another button tells it to got to a different part of the timeline? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment