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
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
sets the
property of the text field that has focus to
border
6.
To register the
focusListener
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.
focusListener
property of the text field that does not have focus to
border
object to receive events from the Selection object, add the
that defines an
onSetFocus
.
true
Using event listeners with components
property
, and
false
335
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?