
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Issues with Nested Assets
|
327
In many ways, the composition version of the Avatar class is cleaner and more flexi-
ble than its MovieClip subclass counterpart—cleaner because it uses fewer methods
and a traditional constructor, more flexible because it can easily change the
av_mc to
some other movie clip symbol if required. However, the MovieClip subclass version
would still be preferable in the following situations:
• When Avatar instances need to belong to the MovieClip datatype (e.g., for the
sake of polymorphism)
• When the Avatar class and the AvatarSymbol movie clip symbol need to be
packaged together as a component for distribution
• When Avatar instances need most of the methods of the MovieClip class (in
which case the “Is-A” relationship is legitimate)
Issues with Nested Assets
Movie clip symbols can contain other nested movie clips, text fields, or components
(i.e., elements attached to the clip symbol during authoring or at runtime). To access
and use these nested assets, we must sidestep two issues.
av_mc = target.attachMovie("AvatarSymbol", name, depth);
setState(Avatar.HAPPY);
setPosition(x, y);
}
public function setState(newState:Number):Void {
switch (newState) {
case Avatar.HAPPY:
av_mc.gotoAndStop("HAPPY");
break;
case Avatar.SAD:
av_mc.gotoAndStop("SAD");
break;