Accordion.createChild()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

accordionInstance.createChild(classOrSymbolName, instanceName[, initialProperties]) 

Parameters

classOrSymbolName Either the constructor function for the class of the UIObject to be instantiated, or the linkage name (a reference to the symbol to be instantiated). The class must be UIObject or a subclass of UIObject, but most often it is View object or a subclass of View.

instanceName The instance name of the new instance.

initialProperties An optional parameter that specifies initial properties for the new instance. You can use the following properties:

Returns

A reference to an instance of the UIObject that is the newly created child.

Description

Method (inherited from View); creates a child for the accordion. The newly created child is added to the end of the list of children owned by the accordion. Use this method to place views inside the accordion. The created child is an instance of the class or movie clip symbol specified in the classOrSymbolName parameter. You can use the label and icon properties to specify a text label and an icon for the associated accordion header for each child in the initialProperties parameter.

When each child is created, it is assigned an index number in the order of creation and the numChildren property is increased by 1.

Example

Start with an Accordion instance on the Stage named my_acc. Add a symbol to the library with the Linkage Identifier payIcon to be the icon for the child header. The following code creates a child named billing (with the label "Payment") that is an instance of the View class:

var child_obj:Object = my_acc.createChild(mx.core.View, "billing", {label: "Payment", icon: "payIcon"});

The following code also creates a child that is an instance of the View class, but it uses import to reference the constructor for the View class:

import mx.core.View;
var child_obj:Object = my_acc.createChild(View, "billing", {label: "Payment", icon: "payIcon"});

Or, add a movie clip symbol to the library with the Linkage Identifier PaymentForm to be the Accordion child, and the following code creates an instance of PaymentForm named billing as the child of my_acc (this approach is useful for dynamic content where you load the dynamic content into a movie clip symbol, and then make that symbol a child of the Accordion instance):

var child_obj:Object = my_acc.createChild("PaymentForm", "billing", {label: "Payment", icon: "payIcon"});

For a more complex example, keep the Accordion instance my_acc on the Stage. Then drag a Label component and a TextInput component from the Components panel to the current document's library (so that you have both a TextInput symbol and a Label symbol in the library). Paste the following code in the first frame of the main timeline (replacing any code from the previous examples). The following code creates a child that is an instance of the View class named billing, and also adds children to billing to provide labels and text input fields for a form:

import mx.core.View;
import mx.controls.Label;
import mx.controls.TextInput;
var child_obj:Object = my_acc.createChild(View, "billing", {label:"Payment", icon: "payIcon"});
// Create labels as children of the view instance.
var cardType_label:Object = child_obj.createChild(Label, "CardType_label", {_x:10, _y:50});
var cardNumber_label:Object = child_obj.createChild(Label, "CardNumber_label", {_x:10, _y:100});
// Create text inputs as children of the view instance.
var cardTypeInput_ti:Object = child_obj.createChild(TextInput, "CardType_ti", {_x:150, _y:50});
var cardNumberInput_ti:Object = child_obj.createChild(TextInput, "CardNumber_ti", {_x:150, _y:100});
// Fill in labels.
cardType_label.text = "Card Type";
cardNumber_label.text = "Card Number";

Flash CS3