
Define an event listener for the custom component 181
This section describes how to define a simple event listener for the Login button. An event
listener is also known as an event handler. For a lesson on event listeners, see Chapter 12, “Use
an Event Listener,” on page 143.
First, you insert and modify a Label control to test that the event listener is called properly.
1. In Design mode, insert a Label control in the space to the left of the Login button, as
follows:
2. Select the Label control and enter lblTest as the value of the Label’s ID property, and clear
the value of the Text property.
3. Select the Button control and enter handleLoginEvent() in the On Click text box in the
Flex Properties view.
When the user clicks the button, you want the application to call the
handleLoginEvent
function.
Next, you write the listener function.
4. Switch to Source mode and place the insertion point immediately after the opening
<mx:Panel> tag.
5. Start typing <mx:Script> until the full tag is selected in the code hints, press Enter to insert
the tag in your code, and then type the closing angle bracket (>) to complete the tag.
Flex Builder enters an
<mx:Script> script block that also includes a CDATA construct.
NOTE
Developing the user authentication logic for the listener is outside the scope of this
lesson.
NOTE
When using an <mx:Script> script block, you should wrap the contents in a CDATA
construct. This prevents the compiler from interpreting the contents of the script
block as XML, and allows the ActionScript to be properly generated.
Comentários a estes Manuais