O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Virtual Zoo Review

Our game now has two classes: VirtualZoo (the main class) and VirtualPet (which represents the pets in the game). The classes reside in the package zoo, and are stored in plain-text files named VirtualZoo.as and VirtualPet.as, respectively. By requirement of Adobe's ActionScript compilers, VirtualZoo is defined with the public attribute because it is the application's main class. By contrast, VirtualPet is defined with the internal attribute, so it can be used inside the zoo package only.

Example 1-1 shows the code for our game so far. The example also introduces something new—code comments. A code comment is a note meant to be read by programmers only and is completely ignored by the compiler. ActionScript code comments come in two varieties: single line, which start with two slashes (//), and multiline, which start with the character sequence /*, and end with the character sequence */.

This is a single-line comment:

// No one here but us programmers

This is a multiline comment:

/*
No one here
but us programmers
*/

The current code for our zoo game follows.

Example 1-1. Zoo game

// Contents of the file VirtualZoo.as
package zoo {
  public class VirtualZoo {
  }
}

// Contents of the file VirtualPet.as
package zoo {
  internal class VirtualPet {
  }
}

Now let's carry on with the development of our program, starting with the constructor method of our main class, VirtualZoo.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required