Wednesday, November 9, 2011

ActionScript 3.0: play and play again buttons

To design a game in flash using ActionScript 3.0, click play button to start a game. After the game over, click "Play Again" button to restart the game.

1) Start Flash CS5, click new-> actionscript 3.0, name your fla  fileas myGame.fla, set class: myGame in property menu.
2) Create 3 frames, the first frame name: "start", second frame name: "play", the third frame name: "gameover"
3) In "start" frame, create a button instance name: startButton
Press F9, enter following actionscript:
//stop at first frame
//When mouse click startButton, call function clickStart
function clickStart(event:MouseEvent) {
//go to "play" frame
4) In "play" frame, create your game. for example, you can create a MovieClip and you can call a function from actionscript file.

5) In "gameover" frame, create a button called "playAgainButton". Press F9 to enter following actionscript:
//When mouse click "playAgainButton" button, call clickPlayAgain function
function clickPlayAgain(event:MouseEvent) {
//go to "play" frame

No comments:

Post a Comment