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
“Using data binding with custom properties”
on page 132
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.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...