
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating and Invoking the Subclass Constructor
|
377
Creating and Invoking
the Subclass Constructor
For now, our Ball constructor (from Example 14-1) is defined on the main timeline
of our .fla file. Later, we’ll see how to move the constructor to our ballSymbol
Library symbol. The Ball constructor looks very much like the constructor functions
we saw in Chapter 12, with the added feature that it is defined in a global namespace
corresponding to the domain name,
moock.org (your classes should be defined in
your domain’s namespace, as in
com.yoursite.YourClass):
/*
* Ball Class Constructor.
*/
org.moock.Ball = function ( ) {
// Create Instance properties.
// ...
// Initialize instance.
// ...
};
However, you’ll notice that our class constructor does not define any parameters!
Remember that we’re creating a MovieClip subclass, and movie clip instances are not
created with the standard new Object() instantiation, which facilitates parameters.
Instead, movie clip instances are created with the functions attachMovie() or
duplicateMovieClip(), which generate the instance and invoke its class constructor (if
one is defined). Hence, to supply arguments to our Ball constructor function, we
have to pass them through either attachMovie() or duplicateMovieClip(). But we can’t
pass the arguments directly, ...