MACROMEDIA FLEX-CREATING ADVANCED COMPONENTS Manual page 16

Creating advanced components
Table of Contents

Advertisement

For example, you define a component called ModalText as the following example shows:
[Event("myEvent")]
class ModalText extends UIComponent {
...
}
Within the body of your class definition, you then use the
. You can then handle the event in MXML as the following example shows:
myEvent
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*" >
<mx:Script>
<![CDATA[
function handleText(event)
{
...
}
]]>
</mx:Script>
<ModalText ... textChanged="handleText(event);" />
</mx:Application>
For more information on events, see Developing Flex Applications.
Defining event handlers for child components
Custom components implement the
other components) in the custom component. To create a subobject, you use the
createClassObject()
function createChildren():Void {
createClassObject(TextInput, "text_mc", 0, {preferredWidth: 80,
editable:false});
text_mc.addEventListener("change", this);
}
This example creates a TextInput control as a child of your custom component. Note that the
createChildren()
an event handler for the
You can define the event handler function that listens for your events in your component's
ActionScript definition. The following example handles the
of the children of the component:
function handleEvent(evt:Object):Void {
if (evt.type == "change") {
dispatchEvent({ type: "change" });
} else if (evt.type == "focusOut") {
text_mc.editable = false;
} else if (evt.type = "click") {
text_mc.editable = !text_mc.editable;
}
}
By default, Flex calls the
16
Creating Advanced Components
createChildren()
method, as the following example shows:
method also contains a call to the
event generated by the TextInput control.
change
method of a component whenever it generates an event.
handleEvent()
dispatchEvent()
method to create subobjects (such as
addEventListener()
,
change
focusOut
method to dispatch
method to register
, and
events
click

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents