
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Curiouser and Curiouser
|
331
would inherit the behavior of the Avatar class, it would not inherit Avatar’s physical
movie clip symbol. Hence, to create the RandomAvatar class, we’d have to create a
completely separate symbol, RandomAvatarSymbol, that is a duplicate of
AvatarSymbol.
Duplicating a symbol merely for the sake of subclassing is neither practical nor wise
in most cases. The better approach is (yet again) to use composition. When a class
uses a movie clip symbol via composition, the class can easily be subclassed,
allowing reuse both of its code and of the movie clip symbol associated via composi-
tion. Example 13-3 shows how we could create the RandomAvatar class as a sub-
class of the Avatar class shown earlier in Example 13-2. Neither Avatar nor
RandomAvatar are MovieClip subclasses. We use composition to associate them with
a movie clip symbol.
For comparison, the example files for the inheritance and composition versions of
the RandomAvatar class are posted at http://moock.org/eas2/examples.
Curiouser and Curiouser
MovieClip subclasses are an enigmatic aspect of object-oriented Flash development.
As we’ve seen, given the option, it’s often better to use composition to associate a
class with a movie clip symbol rather than to extend MovieClip. In the next chapter,
however, ...