User Guide

Table Of Contents
68 Chapter 3: Creating Advanced Components in Flash MX 2004
The event object has an implicit property, target, that is a reference to the object that triggered
the event.
For more information on events, see Developing Flex Applications.
Defining event handlers
You define the event handler object or event handler function that listens for your component’s
events in your applications ActionScript. The following example handles the
change, focusOut,
and
click events 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;
}
}
Using the Event metadata
Add Event metadata in your ActionScript class file for each event listener. The value of the
Event
keyword becomes the first argument in calls to the
addEventListener() method, as the
following example shows:
[Event("click")] // Event declaration.
...
class FCheckBox{
function addEventListener(eventName:String, eventHandler:Object) {
... // eventName is String
}
}
Event metadata describes the events that this component emits, not the ones it consumes. For
more information on the
Event metadata keyword, see “Event” on page 62.
About invalidation
Macromedia recommends that a component not update itself immediately in most cases, but
instead save a copy of the new property value, set a flag indicating what is changed, and call one of
the three invalidation methods.
The following are the invalidation methods:
invalidateSize() Indicates that one of the _measured properties may have changed. This results
in a call to the
measure() method. If the measure() method changes the value of one of the
_measured properties, it calls the layoutChildren() method.
invalidateLayout() Indicates that the position and/or size of one of the subobjects may have
changed, but the
_measured properties have not been affected. This results in a call to the
layoutChildren() method. If you change a subobject in the layoutChildren() method, you
should call the
invalidate() method.