User Guide
154 Chapter 2: ActionScript Language Reference
Button.onSetFocus
Availability
Flash Player 6.
Usage
my_btn.onSetFocus = function(oldFocus:Object) : Void {
// your statements here
}
Parameters
oldFocus
The object to lose keyboard focus.
Returns
Nothing.
Description
Event handler; invoked when a button receives keyboard focus. The oldFocus parameter is the
object that loses the focus. For example, if the user presses the Tab key to move the input focus
from a text field to a button,
oldFocus contains the text field instance.
If there is no previously focused object,
oldFocus contains a null value.
Example
The following example demonstrates how you can execute statements when the user of a SWF file
moves focus from one button to another. Create two buttons,
btn1_btn and btn2_btn, and
enter the following ActionScript in Frame 1 of the Timeline:
Selection.setFocus(btn1_btn);
trace(Selection.getFocus());
btn2_btn.onSetFocus = function(oldFocus) {
trace(oldFocus._name + “ lost focus”);
};
Test the SWF file by pressing Control+Enter. Make sure you select Control > Disable Keyboard
Shortcuts if it is not already selected. Focus is set on
btn1_btn. When btn1_btn loses focus and
btn2_btn gains focus, information is displayed in the Output panel.