
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
386
|
Chapter 14: Movie Clip Subclasses and Components
Component Template
The following code presents a generic component template that implements a
MovieClip subclass. The template does not use a namespace, such as
org.moock,as
we did in our Ball example. Nor does the template store all constructor parameters
on a single
params object. These optional techniques can be implemented at your dis-
cretion. However, the template expects constructor parameters to be prefixed with
cp_, and it deletes all component parameters after construction. Though deleting
constructor parameters is not mandatory, it is wise coding practice.
// CODE PLACED ON FRAME 1 OF someClassSymbol IN THE LIBRARY.
#initclip
/*
* SomeClass Class. Extends MovieClip
* Version: 1.0.0
* Desc: Your description goes here
*
* Component Params:
* cp_param1 -Short description
* cp_param2 -Short description
*
* Methods:
* someMethod( ) -Short description
*/
/*
* Class Constructor
* (Parameters are passed by an initObj or set as component parameters)
*/
_global.SomeClass = function ( ) {
// Create Instance properties
this.prop1 = this.cp_param1;
// Initialize instance
this.someMethod(this.cp_param2);
// Remove component params (those with the cp_ prefix) from the instance
for (var p in this) {
if (p.indexOf("cp_") != -1) {
delete ...