Using the FocusManager

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 FocusManager looks for an enabled object with a tabIndex property that is higher than the current value of tabIndex. Once the FocusManager 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;

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 in the following:

focusManager.defaultPushButton = okButton;

Note: The FocusManager 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.

FocusManager parameters

There are no authoring parameters for the FocusManager. You must use the ActionScript methods and properties of the FocusManager class in the Actions panel. For more information, see FocusManager class.

Creating an application with the FocusManager

The following procedure creates a focus scheme in a Flash application.

  1. Drag the TextInput component from the Components panel to the Stage.
  2. In the Property inspector, assign it the instance name comment.
  3. Drag the Button component from the Components panel to the Stage.
  4. In the Property inspector, assign it the instance name okButton and set the label parameter to OK.
  5. In Frame 1 of the Actions panel, enter the following:
    comment.tabIndex = 1;
    okButton.tabIndex = 2;
    focusManager.setFocus(comment);
    focusManager.defaultPushButton = okButton;
    lo = new Object();
    lo.click = function(){
      trace("button was clicked");
    }
    okButton.addEventListener("click", lo);
    

    This code sets the tab ordering and specifies a default button to receive a click event when a user presses Enter (Windows) or Return (Macintosh).