
Button.onPress() Event Handler
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
466
|
ActionScript Language Reference
• 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 prop-
erty 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().
Example
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 ...