User Guide

162 Creating Components
Defining the init() method
Flash calls the init() method when the class is created. This method is called only once
when a component is instantiated.
You should use the
init() method to do the following:
Call super.init().
This is required.
Make the boundingBox_mc invisible.
boundingBox_mc.width = 0;
boundingBox_mc.height = 0;
boundingBox_mc.visible = false;
Create instance member variables.
The
width, height, and clip parameters are properly set only after this method is called.
The
init() method is called from UIObjects constructor, so the flow of control climbs up
the chain of constructors until it reaches UIObject. UIObject’s constructor calls the
init()
method that is defined on lowest subclass. Each implementation of
init() should call
super.init() so that its base class can finish initializing. If you implement an init()
method and you dont call
super.init(), the ()init method is not called on any of the base
classes, so they might never be in a usable state.
Defining the createChildren() method
Components implement the createChildren() method to create subobjects (such as other
components) in the component. Rather than calling the subobject’s constructor in the
createChildren() method, call createClassObject() or createObject() to instantiate a
subobject of your component.
It’s a good idea to call
size() within the createChildren() method to make sure all
children are set to the correct size initially. Also, call
invalidate() within the
createChildren() method to refresh the screen. (For more information, see About
invalidation” on page 166.)
The
createClassObject() method has the following syntax:
createClassObject(className, instanceName, depth, initObject)