EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Using Event Listeners with Components

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Using event listeners with components 335
5. To create an object that listens for focus notification from the Selection class, enter the
following code in the Actions panel:
// Creates listener object, focusListener.
var focusListener:Object = new Object();
// Defines function for listener object.
focusListener.onSetFocus = function(oldFocus_txt:TextField,
newFocus_txt:TextField) {
oldFocus_txt.border = false;
newFocus_txt.border = true;
}
This code creates an object named focusListener that defines an onSetFocus property
and assigns a function to the property. The function takes two parameters: a reference to
the text field that does not have focus and one to the text field that has focus. The
function sets the
border property of the text field that does not have focus to false, and
sets the
border property of the text field that has focus to true.
6. To register the focusListener object to receive events from the Selection object, add the
following code to the Actions panel:
// Registers focusListener with broadcaster.
Selection.addListener(focusListener);
7.
Test the application (Control > Test Movie), click in the first text field, and press the Tab
key to switch focus between fields.
Using event listeners with components
When you work with components, you have a slightly different event-listener syntax.
Components generate events, and you must specifically listen for these events by using either
a listener object or a custom function.
The following example shows how you can use event listeners to monitor the download
progress of a dynamically loaded image.
To listen for Loader component events:
1. Drag an instance of the Loader component onto the Stage from the Components panel.
2. Select the loader, and type my_ldr in the Instance Name text box in the Property inspector.

Table of Contents

Related product manuals