Using Focus Manager

The Focus Manager does not automatically assign focus to a component. You must write a script that calls FocusManager.setFocus() on a component if you want a component to have focus when an application loads.

NOTE

 

If you call FocusManager.setFocus() to set focus to a component when an application loads, the focus ring does not appear around that component. The component has focus, but the indicator is not present.

To create focus navigation in an application, set the tabIndex property on any objects (including buttons) that should receive focus. When a user presses the Tab key, the Focus Manager looks for an enabled object with a tabIndex property that is higher than the current value of tabIndex. Once the Focus Manager reaches the highest tabIndex property, it returns to zero. So, in the following example, the comment object (probably a TextArea component) receives focus first, and then the okButton object receives focus:

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 (stacking order, or z-order). The depth is 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 depth.

To create a button that receives focus when a user presses Enter (Windows) or Return (Macintosh), set the FocusManager.defaultPushButton property to the instance name of the desired button, as shown here:

focusManager.defaultPushButton = okButton;

NOTE

 

The Focus Manager is sensitive to when objects are placed on the Stage (the depth order of objects) and not their relative positions on the Stage. This is different from the way Flash Player handles tabbing.

Related topics

Using Focus Manager to allow tabbing

You can use the Focus Manager to create a scheme that allows users to press the Tab key to cycle through objects in a Flash application. (Objects in the tab scheme are called tab targets.) The Focus Manager examines the tabEnabled and tabChildren properties of the objects' parents in order to locate the objects.

A movie clip can be either a container of tab targets, a tab target itself, or neither:

Movie clip type

tabEnabled

tabChildren

Container of tab targets

false

true

Tab target

true

false

Neither

false

false

NOTE

 

This is different from the default Flash Player behavior, in which a container's tabChildren property can be undefined.

Consider the following scenario. On the Stage of the main timeline are two text fields (txt1 and txt2) and a movie clip (mc) that contains a DataGrid component (grid1) and another text field (txt3). You would use the following code to allow users to press Tab and cycle through the objects in the following order: txt1, txt2, grid1, txt3.

NOTE

 

The FocusManager and TextField instances are enabled by default.

// Let Focus Manager know mc has children;
// this overrides mc.focusEnabled=true;
mc.tabChildren=true; 
mc.tabEnabled=false;
// Set the tabbing sequence.
txt1.tabIndex = 1;
txt2.tabIndex = 2;
mc.grid1.tabIndex = 3;
mc.txt3.tabIndex = 4;

// Set initial focus to txt1.
txt1.text = "focus";
focusManager.setFocus(txt1);

If your movie clip doesn't have an onPress or onRelease method or a tabEnabled property, it won't be seen by the Focus Manager unless you set focusEnabled to true. Input text fields are always in the tab scheme unless they are disabled.

If a Flash application is playing in a web browser, the application doesn't have focus until a user clicks somewhere in the application. Also, once a user clicks in the Flash application, pressing Tab can cause focus to jump outside the Flash application. To keep tabbing limited to objects inside the Flash application in Flash Player 7 ActiveX control, add the following parameter to the HTML <object> tag:

<param name="SeamlessTabbing" value="false"/>

Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00003120.html