13.1 The Duality of MovieClip Subclasses

 <  Day Day Up  >  

Every MovieClip subclass has two parts : a movie clip symbol and a corresponding ActionScript 2.0 class. Like any other subclass, a MovieClip subclass uses the extends keyword to inherit from MovieClip :

 class   SomeClass    extends  MovieClip { } 

However, a MovieClip subclass must also be represented physically in a Flash document Library by a movie clip symbol. The movie clip symbol in the Library specifies the class that represents it, thus coupling the symbol and MovieClip subclass together. In the vast majority of cases, this symbol-to-class relationship is a one-to-one relationship. That is, a single movie clip symbol is associated with a single MovieClip subclass. In fact, it's not even possible to associate a single symbol with more than one class. However, multiple movie clip symbols can legally each associate itself with the same MovieClip subclass. This allows different symbols, each with its own artwork, to adopt the behavior defined by a single class. However, in most cases, associating multiple movie clip symbols with a single MovieClip subclass is bound to become confusing. Use this "many symbols to one class" approach with caution.

To create instances of a MovieClip subclass, we do not use the new operator as we would with a typical class. Instead, instances of the movie clip subclass's symbol (not the subclass itself) are created either manually in the authoring tool or programmatically via attachMovie( ) or duplicateMovieClip( ) . It is, hence, not possible to create a functioning MovieClip subclass without a corresponding movie clip symbol in the Library of a .fla file.

Note that the Flash community uses the term "movie clip" to refer to both movie clip instances on stage and movie clip symbols in the Library. The difference is usually clear from context. For example, if I say, "All movie clips must be stored as symbols in the Library." you understand that I mean "all movie clip symbols must be stored in the Library." But in this chapter, loose terminology can get us in trouble. So I'll differentiate explicitly between "movie clip instances on stage" and "movie clip symbols in the Library" whenever necessary.

Let's see how this all works in practice by creating a real MovieClip subclass. The example files discussed in this chapter are available at http:// moock .org/eas2/examples.

 <  Day Day Up  >  


Essential ActionScript 2.0
Essential ActionScript 2.0
ISBN: 0596006527
EAN: 2147483647
Year: 2004
Pages: 177
Authors: Colin Moock

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net