Flash CS3 Documentation |
|||
| Using ActionScript 2.0 Components > Working with Components > Creating custom focus navigation | |||
When a user presses the Tab key to navigate in a Flash application or clicks in an application, the FocusManager class determines which component receives input focus (for more information see "FocusManager class" in the ActionScript 2.0 Components Language Reference). You don't need to add a FocusManager instance to an application or write any code to activate the Focus Manager.
If a RadioButton object receives focus, the Focus Manager examines that object and all objects with the same groupName value and sets focus on the object with the selected property set to true.
Each modal Window component contains an instance of the Focus Manager, so the controls on that window become their own tab set. This prevents a user from inadvertently navigating to components in other windows by pressing the Tab key.
To create focus navigation in an application, set the tabIndex property on any components (including buttons) that should receive focus. When a user presses the Tab key, the FocusManager class looks for an enabled object whose tabIndex value is greater than the current value of tabIndex. After the FocusManager class reaches the highest tabIndex property, it returns to 0. For example, in the following code, the comment object (probably a TextArea component) receives focus first, and then the okButton instance receives focus:
var comment:mx.controls.TextArea; var okButton:mx.controls.Button; comment.tabIndex = 1; okButton.tabIndex = 2;
You can also use the Accessibility panel to assign a tab index value.
If nothing on the Stage has a tab index value, the Focus Manager uses the depth levels (z-order). The depth levels are set up primarily by the order in which components are dragged to the Stage; however, you can also use the Modify > Arrange > Bring to Front/Send to Back commands to determine the final z-order.
To give focus to a component in an application, call FocusManager.setFocus().
To create a button that receives focus when a user presses Enter (Windows) or Return (Macintosh), set the FocusManager.defaultPushButton property to the instance of the desired button, as in the following code:
focusManager.defaultPushButton = okButton;
The FocusManager class (API) overrides the default Flash Player focus rectangle and draws a custom focus rectangle with rounded corners.
For more information about creating a focus scheme in a Flash application, see the FocusManager class in the ActionScript 2.0 Components Language Reference.
Flash CS3