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.)

The createClassObject() method has the following syntax:

createClassObject(className, instanceName, depth, initObject)

The following table describes the parameters:

Parameter

Type

Description

className

Object

The name of the class.

instanceName

String

The name of the instance.

depth

Number

The depth for the instance.

initObject

Object

An object that contains initialization properties.

To call createClassObject(), you must know what the children are, because you must specify the name and type of the object, plus any initialization parameters in the call to createClassObject().

The following example calls createClassObject() to create a new Button object for use inside a component:

up_mc.createClassObject(mx.controls.Button, "submit_btn", 1);

You set properties in the call to createClassObject() by adding them as part of the initObject parameter. The following example sets the value of the label property:

form.createClassObject(mx.controls.CheckBox, "cb", 0, {label:"Check this"});

The following example creates TextInput and SimpleButton components:

function createChildren():Void {
    if (text_mc == undefined)
        createClassObject(TextInput, "text_mc", 0, { preferredWidth: 80,     editable:false });
        text_mc.addEventListener("change", this);
        text_mc.addEventListener("focusOut", this);

    if (mode_mc == undefined)
        createClassObject(SimpleButton, "mode_mc", 1, { falseUpSkin: modeUpSkinName, falseOverSkin: modeOverSkinName, falseDownSkin: modeDownSkinName });
    mode_mc.addEventListener("click", this);
    size()
    invalidate()
}

Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00002509.html