User Guide

18 Creating Interactivity and Navigation
Customizing the focus rectangle
The focus rectangle is a default yellow highlight that indicates which button or input text box
is currently selected. Movie clips are also included if their
tabEnabled property is set to true,
or if they have event handlers associated with them and their
tabEnabled property is not set
to
false. For more information, see About the focus rectangle” on page 16.
You can disable the default focus rectangle behavior by setting the global
_focusRect
property to
false. You can also disable the focus rectangle for specific buttons or movie clips
(see
_focusrect (Button._focusrect property) and _focusrect
(MovieClip._focusrect property)
) in the Flash Lite 2.x ActionScript Language Reference.
You can also change the color of the focus rectangle from the default yellow to any other color.
To do this you use the
SetFocusRectColor command, which takes RGB values as
parameters. For example, the following code changes the color of the focus rectangle to red:
fscommand2("SetFocusRectColor", 255, 0, 0);
Controlling focus with ActionScript
You can use the Selection ActionScript object to get and set the current keypad focus, or to be
notified when an object receives or loses keypad focus. This is useful, for example, if you want
to automatically set the focus to a specific button when your application first loads. Or you
may want to be notified when a specific object on the screen has received (or lost) keypad
focus so that you can update the screen accordingly.
For example, the following code uses the
Selection.setFocus() method to set focus to the
button instance named
login_btn:
Selection.setFocus(login_btn);
The Selection.onSetFocus event listener lets you determine when the keypad focus has
changed. You can use this event listener, for example, to create a custom focus manager for
input text fields, rather than use the default focus rectangle. The following procedure shows
how to create a custom focus manager that changes the border color of the TextField object
with focus. A completed version of this application named custom_input_focus.fla is located
in the /Sample and Tutorials/Samples/Flash Lite 2.0/ folder in the Flash Professional 8
installation folder on your computer.
To create a custom text input focus manager:
1. Create a new document from the Flash Lite 2.0 Generic document template that you
created in “Creating a Flash Lite document template (Flash Professional only)” in Getting
Started with Flash Lite 2.x, and save it as custom_input_focus.fla.
2. Using the Text tool, create a text field on the Stage.