Macromedia flex 2 Manual
174
Creating Advanced Visual Components in ActionScript
However, if a child component dispatches an event, and you want that opportunity to handle
the event outside of the component, you must add logic to your custom component to
propagate the event. Notice that the event listener for the
the event outside of the component, you must add logic to your custom component to
propagate the event. Notice that the event listener for the
change
event for the TextArea
control propagates the event. This lets you handle the event in your application, as the
following example shows:
following example shows:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:Script>
<![CDATA[
import flash.events.Event;
function handleText(eventObj:Event)
{
{
...
}
]]>
</mx:Script>
<MyComp:ModalText changed="handleText(event);"/>
</mx:Application>
Creating the ModalText component
The following code example implements the class definition for the ModalText component.
The ModalText component is a composite component that contains a
The ModalText component is a composite component that contains a
Button
control and a
TextArea
control. The following image shows this control:
This control has the following attributes:
■
You cannot edit the TextArea control by default.
■
You click the Button control to toggle editing of the TextArea control.
■
You use the
textPlacement
property of the control to make the TextArea appear on the
right side or the left side of the control.
■
Editing the
textPlacement
property of the control dispatches the
placementChanged
event.
■
You use the
text
property to programmatically write content to the TextArea control.
■
Editing the
text
property of the control dispatches the
textChanged
event.
■
Editing the text in the TextArea control dispatches the
change
event.