
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
278
|
Chapter 12: Objects and Classes
for example, have properties specific to individual movie clips, such as their number
of frames (
_totalframes) and position on screen (_x and _y).
Traditionally, object properties are set via methods of the object to preserve the
encapsulated nature of an object. That is, in strict OOP, an object should set its own
properties. If an outside entity wants to set an object’s property, it should do so by
calling an appropriate method of the object. For example, a purist would frown on
setting the
_width property of a movie clip directly. The purist would argue that it is
best to let the movie clip object set the
_width property itself, and that code outside
of the object should do so only indirectly, by calling one of the movie clip object’s
methods (say, setWidth()). By moderating access to properties with method calls, the
maintainer of the MovieClip class could change the name of the
_width property to w
without adversely affecting other users of the class.
Instantiating Objects
Although it may sound backward, let’s assume that we have already created an
object class. This assumption isn’t too ludicrous, because ActionScript provides
many built-in classes, and the custom classes we’ll build will behave similarly.
Assuming we have an object class, we have ...