EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Page 86

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT
816 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...
86 Chapter 4: Handling Events
To create a simple focus manager with event listeners:
1 Using the Text tool, create a text field on the Stage.
2 Select the text field and, in the Property inspector, select Input from the Text Type pop-up
menu, and select the Show Border Around Text option.
3 Create another input text field below the first one.
Make sure the Show Border Around Text option is not selected for this text field. Continue to
create input text fields if desired.
4 Select Frame 1 in the Timeline and open the Actions panel (Window > Development
Panels > Actions).
5 To create an object that listens for focus notification from the Selection class, enter the following
code in the Actions panel:
var focusListener = new Object();
focusListener.onSetFocus = function(oldFocus_txt, newFocus_txt) {
oldFocus_txt.border = false;
newFocus_txt.border = true;
}
This code creates a new (generic) ActionScript object named focusListener. This object
defines for itself an
onSetFocus property, to which it assigns a function. The function takes
two parameters: a reference to the text field that lost focus, and one to the text field that gained
focus. The function sets the
border property of the text field that lost focus to false, and sets
the
border property of the text field that gained focus to true.
6 To register the focusListener object to receive events from the Selection object, add the
following code to the Actions panel:
Selection.addListener(focusListener);
7 Test the movie (Control > Test Movie), click in the first text field, and press Tab to switch focus
between fields.
To unregister a listener object from receiving events, you call the
removeListener() method of
the broadcaster object, passing it the name of the listener object.
broadcastObject.removeListener(listenerObject);
Event listeners are available to objects of the following ActionScript classes: Key, Mouse,
MovieClipLoader, Selection, TextField, and Stage. For a list of event listeners available to each
class, see these class entries in Chapter 12, ā€œActionScript Dictionary,ā€ on page 205.

Table of Contents

Related product manuals