How to play from start on click Flash AS2 / AS3

This article was written by in February 17, 2015, & may not be posted on other sites!
Original source url for this article: How to play from start on click Flash AS2 / AS3

How to play from start on click Flash AS2 / AS3.
How to play flash movie from the beginning of the timeline on click of a button or movieclip. Full code examples below. This is how to play from start on click Flash AS2 / AS3.

How to play from start on click Flash AS2 or AS3

AS3

Assuming you have a button or movieclip with the instance name of “my_btn”, this AS3 code will work:

To play the movie from start on beginning of timeline on click, use this code:
function playFromBeginning(event:MouseEvent):void {
gotoAndPlay(1);
}

my_mc.addEventListener(MouseEvent.CLICK, playFromBeginning);

To play a specific movieclip from start on click, use this code
function playAnimation(event:MouseEvent):void
{
animation_mc.play();
}
my_mc.addEventListener(MouseEvent.CLICK, playAnimation);

 

AS2

Assuming you have a button or movieclip with the instance name of “my_mc”, this AS2 code will work:

To play the movie from start on beginning of timeline on click, use this code:
stop();
my_mc.onRelease = function() {
this._parent.play();
};

To play a specific movieclip from start on click, use this code
animation_mc.stop();
my_mc.onRelease = function(){
animation_mc.play();
};

 

 

How to give a movieclip or button an instance name in Flash?

Create a movieclip or a button and place it on the stage. Select it and go to the properties panel. There is a field called “instance name”, fill this out. NOTE: the AS function cannot be placed before the movieclip on the timeline, then the function will give an error not finding the movieclip. For example if the movieclip is placed on the timeline in frame 10, the Actionscript function cannot be placed before frame 10.
How to play from start on click Flash AS2  AS3, play movie from beginning of timeline

 

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *