Monday, September 6, 2010

Code for Your Replay Button

This is the code you will use when you do your "Play Again" button. It is Actionscript 3.o, and you will put this code on an Actions layer you create on the last frame of your animation.

function MyButtonClicked(evt:MouseEventArgs):void
{
gotoAndPlay(1);
}

MyButton.addEventListener(MouseEvent.CLICK, MyButtonClicked);

MyButtonClicked and MyButton are variable names that can be named whatever you want them to be.

The button you create will have the instance name "MyButton" or whatever you like; name the instance by selecting your button object and typing the name in on the Properties panel Instance form field.

I'll talk about this in class this week. Take care!

1 comment:

Jonathan Hart said...

If you are using scenes and you want it to go back to Frame 1 of Scene 1 then use the code Paige posted here but change gotoAndPlay(1); to:

{
gotoAndPlay(1, "Scene 1");
}

If you have given your scene a name then use that instead of "Scene 1"