
148 Use an Event Listener
2. Save the file, wait until Flex Builder compiles the application, and click Run in the toolbar.
If you’re using the plug-in configuration of Flex Builder, select Run > Run As > Flex
Application.
A browser opens and runs the application.
3. Enter a price and click the Convert to Yen button.
The Label control below the TextInput control displays the price in yen.
Associate the listener with an event with
ActionScript
You can use ActionScript to associate a listener with a specific event, such as a mouse click.
When the event fires, the listener is notified and runs.
1. Switch to Source mode.
2. Delete the click property and its value in the <mx:Button> tag.
3. Declare an argument of type MouseEvent, or a subclass of the MouseEvent class, in the
signature of your
convertCurrency event listener as follows (in bold):
public function convertCurrency(e:MouseEvent):void {
...
In this example, the listener function takes an object of type flash.Events.MouseEvent, a
subclass of the Event class. When a listener function is invoked, Flex implicitly creates a
MouseEvent object for you and passes it to the listener function. Therefore, it is best
practice to declare a MouseEvent object in the signature of your listener function.
Accordingly, you declare an object of type MouseEvent, called e, in the signature of the
convertCurrency function.
Commentaires sur ces manuels