Button.onKillFocus( ) Event Handler | Flash 6 |
callback invoked when the button loses focus |
The TextField, MovieClip, or Button object that now has focus, or null if no object has received focus.
The onKillFocus( ) event handler is triggered when theButton loses focus. A button is said to "have focus" when:
The user navigates to it using the Tab key.
Selection.setFocus( ) assigns it focus programmatically.
When _focusrect is true or null (null is the default) a yellow rectangle appears around the focused button. A button loses focus when:
The user navigates to a different button, text field, or movie clip using the Tab key.
Selection.setFocus( ) assigns focus to another object programmatically. (The newly focused object is accessible within onKillFocus( ) via newFocus.)
The user moves the mouse.
In the first two cases, onKillFocus( ) is executed. In the last case, due to a bug in Flash Player 6, onKillFocus( ) is not executed, but it should be. When a button's tabEnabled property is false, the button cannot be focused by the user but can be focused programmatically with Selection.setFocus( ). To capture all focus events centrally, rather than for a single instance, use Selection.onSetFocus( ).
The following example adds callback handlers, for onSetFocus( ) and onKillFocus( ), to cancel_btn. It also creates a text field that displays the focus status. Finally, it focuses cancel_btn. To try the code, create two buttons, one called "cancel_btn". Then run the movie in the Standalone Player and press the Tab key (without touching the mouse!). If you test in a browser, you must first click the movie before pressing Tab.
this.createTextField("status_txt", 1, 0, 0, 300, 20); status_txt.border = true; cancel_btn.onKillFocus = function () { // Handle event... status_txt.text = ("killfocus detected for cancel_btn"); }; cancel_btn.onSetFocus = function () { // Handle event... status_txt.text = ("setfocus detected for cancel_btn"); }; Selection.setFocus(cancel_btn);
Button.onSetFocus( ), Selection.onSetFocus( ), Selection.setFocus( ), MovieClip.onKillFocus( ), TextField.onKillFocus( ); Chapter 10