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.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...