Game Development Reference
In-Depth Information
}
}
public function initGame():void {
stage.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
clicks = 0;
gameState = STATE_PLAY;
}
public function playGame() {
if (clicks >=10) {
gameState = STATE_GAME_OVER;
}
}
public function onMouseClickEvent(e:MouseEvent) {
clicks++;
trace("mouse click number:" + clicks);
}
public function gameOver():void {
stage.removeEventListener(MouseEvent.CLICK, onMouseClickEvent);
gameState = STATE_INIT;
trace("game over");
}
}
}
Testing the game
Why not go ahead and test the game?
This might be a good time to download the code for the topic from the web address printed on the
back cover.
If you are new to AS3 and you are using the Flash IDE, you can test this game as follows:
1.
Save the code as Game.as .
2.
Create a new Flash AS3 .fla document named clickgame.fla in the IDE, and save it
in the same directory as Game.as .
3.
Set the Document property in the Flash IDE for your new .fla document to Game.
4.
In the Modify Document menu, set the dimensions for the game to 550
400.
5.
Test the game by pressing Ctrl/Cmd+Enter or using the Control Test Movie menu option.
6.
You can find the code for this game in /source/projects/ch1_clickgame in the
downloaded source.
Note that if you are interested in making games without the Flash IDE, we will start that process
in Chapter 2. Also, we will reuse this method for nearly every game in this topic, so if you forget,
refer to this chapter to review.
Search WWH ::




Custom Search