Macromedia flex 2 Manual

Página de 254
Defining events in ActionScript components
141
Custom components that extend existing Flex classes inherit all the events of the superclass. If 
you extend the 
Button
 class to create the MyButton class, you can use the events inherited 
from the Button class, such as 
mouseOver
 or 
creationComplete
, as the following example 
shows:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
xmlns:MyComp="myComponents.*"> 
<mx:Script>
<![CDATA[
import flash.events.Event;
private function handleClick(eventObj:Event):void {
// Define event listener.
}
private function handleCreationComplete(eventObj:Event):void {
// Define event listener.
}
]]>
</mx:Script>
<MyComp:MyButton 
click="handleClick(event);" 
creationComplete="handleCreationComplete(event);"/>
</mx:Application>
Your custom components can also define new events based on the requirements of your 
components. For example, the section 
 showed how to define a custom event so that properties of your component can 
work with the Flex data binding mechanism. 
This section describes how to handle events within a custom component and how to create 
events for it.
Handling predefined events within the component
The previous section showed a custom component, MyButton, dispatching two events. In 
that section, you defined the event listeners in the main application file.