User Guide

36 Creating Custom Events
Custom components that extend existing Flex classes inherit all the events of the base class.
Therefore, if you extend the Button class to create the MyButton class, you can use the
click
event, and the events that all controls inherit, such as
mouseOver or initialize, as the
following example shows:
<?xml version="1.0"?>
<!-- events/MyApplication.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:Script>
<![CDATA[
import flash.events.Event;
// Event listener for the click event.
private function handleClick(eventObj:Event):void {
// Define event listener.
}
// Event listener for the initialize event.
private function handleInit(eventObj:Event):void {
// Define event listener.
}
]]>
</mx:Script>
<MyComp:MyButton
click="handleClick(event);"
initialize="handleInit(event);"/>
</mx:Application>
In addition to using the events inherited from its superclasses, your custom components can
define custom events. You use custom events to support data binding, to respond to user
interactions, or to trigger actions by your component.
For more information on the Flex event mechanism, see Chapter 5, “Using Events,” in Flex 2
Developer’s Guide.