
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
16
|
Chapter 2: Object-Oriented ActionScript
The syntax for creating objects (e.g., new SpaceShip( )) is the same in
ActionScript 2.0 as it was in ActionScript 1.0. However, the syntax for
defining classes in ActionScript 2.0 differs from ActionScript 1.0.
Most objects are stored somewhere after they’re created so that they can be used
later in the program. For example, we might store a SpaceShip instance in a variable
named
ship, like this:
var ship:SpaceShip = new SpaceShip( );
Each object is a discrete data value that can be stored in a variable, an array element,
or even a property of another object. For example, if you create 20 alien spaceships,
you would ordinarily store references to the 20 SpaceShip objects in a single array.
This allows you to easily manipulate multiple objects by cycling through the array
and, say, invoking a method of the SpaceShip class on each object.
Object Usage
An object’s methods provide its capabilities (i.e., behaviors)—things like “fire mis-
sile,” “move,” and “scroll down.” An object’s properties store its data, which
describes its state at any given point in time. For example, at a particular point in a
game, our
ship’s current state might be speed is 300, damage is 14.
Methods and properties that are defined as public by an object’s class can be
accessed ...