
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Making Movie Clip Components
|
381
// ========================================
// Class Constructor
org.moock.Ball = function ( ) { ... };
// Set MovieClip as Ball's superclass
org.moock.Ball.prototype = new MovieClip( );
// Associate the Library's ballSymbol with the Ball class
Object.registerClass("ballSymbol", org.moock.Ball);
// Method: Ball.setSize( )
org.moock.Ball.prototype.setSize = function (newRadius) { ... };
// Method: Ball.setPosition( )
org.moock.Ball.prototype.setPosition = function (x, y) { ... };
// Method: Ball.setColor( )
org.moock.Ball.prototype.setColor = function (newColor) { ... };
// Method: Ball.move( )
org.moock.Ball.prototype.move = function ( ) { ... };
#endinitclip
An #initclip block can appear only on frame 1 of a movie clip timeline. If the code
is placed on the main timeline or outside of frame 1 of a movie clip timeline, it gener-
ates a compile-time error. Code within the block is executed once, and only once,
per movie clip symbol, just before the first instance of the symbol is created. By
defining our Ball class inside the ballSymbol’s
#initclip block, we guarantee that the
Ball class constructor will be available before the first instance of ballSymbol appears.
Methods and properties defined by Ball will be available immediately to each new
Ball instance.