
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Properties
|
65
Let’s now add an empty constructor function to our Box class. In the following code,
lines 2 and 3 are the Box class’s constructor function (or, more succinctly, “the Box
constructor”):
class Box {
public function Box ( ) {
}
}
Now that our Box class has an empty constructor function, we’ll give the class some
properties and methods. Once we add properties and methods, we can use them in
the Box constructor to initialize Box instances.
However, we have a lot to learn about properties and methods in the upcoming sec-
tions before we can finish our Box constructor. Hence, we’ll leave it empty for now
and return to it later, under “Constructor Functions (Take 2).” For the sake of brev-
ity, until we return to the Box constructor, we’ll omit it from all intervening code
samples. This omission is legal, if uncommon. When no constructor is provided for a
class, ActionScript adds an empty one automatically at compile time.
Properties
As we learned in Chapter 2, classes use properties to store information. But some
information relates to a class as a whole (e.g., the default size for all SpaceShip objects)
and some information relates to individual objects (e.g., the current speed or position
of each SpaceShip instance). Consequently, properties come in different varieties:
Class properties ...