Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Keeping Score

Keeping score is an effective way of displaying a user's progress throughout the game. This section introduces the concept of scoring in Flash. You will use the dynamic text box on Stage to build the scoring feature of the maze.

  1. Click on the dynamic text box on Stage under the text Score. Using the Properties panel, enter the variable value score and the instance name display.

Figure 5.20Figure 5.20

  1. Click on Frame 1 of the functions layer. Enter this script on Frame 1 right after the mc_move() function:

    Listing 5.15

    function collision(x, y) {
      var mc_name = "t"+x+"_"+y;
      if (cell[mc_name].p.x == x && cell[mc_name].p.y == y) {
       //If the player has grabbed all the balloons, then he wins and the victory sound "done" plays.
       if (score>=winScore) {
         score = "YAY";
       //Removing the movie clip will leave an empty space on the stage where the balloon once was. 

    Here, you create a loop that checks whether the puffin picked up a balloon as the user moved him around the maze. The current tile is being checked each time an arrow key is pressed. If all the balloons are picked, then the user has won and the done sound can start playing.

    If the puffin is in a tile that contains a balloon, you will make the balloon disappear, play the sound grab sound, and add a point to the user's score, as shown in the following two lines from Listing 5.15.

    grab sound.start();

    The score is updated directly in the text field you just created.

    If the score is equal to the total number of balloons (the variable winScore), the user will have won the game, in which case you will play the done sound.

    At this point, you will change the message in the Score box. Otherwise, the player would be stuck wandering around an empty playing field.


    When a balloon has been obtained and a point added to the score, you can remove the tile movie clip instance from the Stage.

  2. Now run the movie and see how it works. Move the puffin around the maze using your arrow keys. Feel free to adjust the speed if you think he's moving too fast or too slow.

Figure 5.21Figure 5.21

  1. Save your work. Well done! You just built a full-blown maze game and kept it under 25Kb.

  • + Share This
  • 🔖 Save To Your Account