158
Creating Advanced Visual Components in ActionScript
// 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
createChildren()
method calls the
addChild()
method to
add the child component. You must call the
addChild()
method for each child object.
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
“Example: Creating a composite component”
on page 172
.
Implementing the commitProperties() method
You use the
commitProperties()
method to coordinate modifications to component
properties. Most often, you use it with properties that affect how a component appears on the
screen.
Flex schedules a call to the
commitProperties()
method when a call to the
invalidateProperties()
method occurs. The
commitProperties()
method executes
during the next
render
event after a call to the
invalidateProperties()
method. When
you use the
addChild()
method to add a component to a container, Flex automatically calls
the
invalidateProperties()
method.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...