MovieClip.focusEnabled Property | Flash 6 |
allow the clip to be focused programmatically | read/write |
When the Boolean focusEnabled property is false or undefined (the default) and mc defines no button handlers (onPress( ), onRelease( ), etc.), mc cannot be focused via Selection.setFocus( ). When focusEnabled is true, mc can be focused via Selection.setFocus( ) at any time, even when no button handlers are defined. When mc defines at least one button handler, it can still be focused via Selection.setFocus( ), even when focusEnabled is false. To disable focus for a movie clip with button handlers, remove the handlers and set focusEnabled to false. For example, the following code removes the onPress( ) handler of theClip_mc:
delete theClip_mc.onPress;
We use focusEnabled when creating movie clips that act as keyboard-controlled interface elements, such as a modal dialog box with Yes and No buttons activated by the keys "Y" and "N." The dialog box should respond to "Y" and "N" only when it has focus. The following code shows a simplified function that creates a dialog box clip and focuses it:
function displayAlert () { // appInterface is a movie clip containing the main application interface. // getFreeDepth(), not shown, is a function that returns an unoccupied // depth on which to place the dialog clip. dialog is the dialog box clip. var dialog = appInterface.attachMovie("dialog", "alertDialog", appInterface.getFreeDepth()); // Allow the dialog box to be focused. dialog.focusEnabled = true; // Focus the dialog box. Selection.setFocus(dialog); }
To highlight our dialog clip when it is focused, we can create frames with the special labels _over and _up in the dialog clip's timeline. The _up and _over frames will be displayed automatically by Flash when the clip loses and receives focus, respectively. You also might want to set the clip's _focusrect property to false. For a discussion of special focus issues for keyboard-controlled movie clips, see MovieClip.onKeyDown( ).
Note that focusEnabled and tabEnabled are not synonyms. Even when focusEnabled is false, a movie clip can be focused with the Tab key when tabEnabled is true. Conversely, setting focusEnabled to true does not enable Tab-focusing for the clip; Tab-focusing is controlled independently by tabEnabled and tabIndex.
MovieClip._focusrect, MovieClip.tabEnabled, MovieClip.tabIndex, TextField.selectable, Selection.setFocus( )