Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 158

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

// Call the createChildren() method of the superclass.
super.createChildren();
// Test for the existence of the children before creating them.
// This is optional, but do this so a subclass can create a different
// child.
if (!text_mc) {
text_mc = new TextArea();
text_mc.explicitWidth = 80;
text_mc.editable = false;
text_mc.addEventListener("change", handleChangeEvent);
// Add the child component to the custom component.
addChild(text_mc);
}
// Test for the existence of the children before creating them.
if (!mode_mc) {
mode_mc = new Button();
mode_mc.label = "Toggle Editing";
mode_mc.addEventListener("click", handleClickEvent);
// Add the child component to the custom component.
addChild(mode_mc);
}
}
Notice in this example that the
add the child component. You must call the
After you create a child component, you can use properties of the child component to define
its characteristics. In this example, you create the Button and TextArea controls, initialize
them, and register event listeners for them. You could also apply skins to the child
components. For a complete example, see
on page
172.
Implementing the commitProperties() method
You use the
commitProperties()
properties. Most often, you use it with properties that affect how a component appears on the
screen.
Flex schedules a call to the
invalidateProperties()
during the next
render
you use the
addChild()
the
invalidateProperties()
158
Creating Advanced Visual Components in ActionScript
createChildren()
addChild()
"Example: Creating a composite component"
method to coordinate modifications to component
commitProperties()
method occurs. The
event after a call to the
method to add a component to a container, Flex automatically calls
method.
method calls the
method for each child object.
method when a call to the
commitProperties()
invalidateProperties()
method to
addChild()
method executes
method. When

Advertisement

Table of Contents
loading

Table of Contents