Table of Contents

TextField.onKillFocus( ) Event Handler Flash 6

callback invoked when the field loses focus
theField.onKillFocus(newFocus)

Arguments

newFocus

The TextField, MovieClip, or Button object that now has focus, or null if no object received focus.

Description

The onKillFocus( ) event is triggered when theField loses focus. A text field is said to have focus when it contains the text insertion point or when characters within it are selected. A field gains focus when:

A field loses focus (and onKillFocus( ) is executed) when:

When a text field's selectable property is false, the field cannot be focused by the user but can be focused programmatically with Selection.setFocus( ).

The following code creates a callback function that responds to onKillFocus( ). Run it in Test Movie mode and try clicking on and off the text field. The Output window displays a message when the event is triggered.

// Create a text field that accepts user input
this.createTextField("theField_txt", 1, 0, 0, 200, 20);
theField_txt.type = "input";
theField_txt.border = true;
// Assign the onKillFocus() callback using a function literal
theField_txt.onKillFocus = function (newFocus) {
  trace(this + " lost focus. Focus is now " + newFocus);
};

Notice that from the body of the callback we refer to theField_txt using the this keyword. To stop a callback from handling the onKillFocus( ) event, use the delete operator, as in:

// Make sure to omit the () operator after the function name!
delete theField_txt.onKillFocus;

The onKillFocus( ) event can be used to trigger the validation of text field input when the user has finished entering text. Or, in combination with onSetFocus( ), it can bring attention to a focused text field with color (see the Example under TextField.onSetFocus( )). To capture all focus events centrally, rather than for a single instance, use Selection.onSetFocus( ).

See Also

Selection.onSetFocus( ), Selection.setFocus( ), TextField.onSetFocus( ), TextField.selectable, TextField.tabEnabled, TextField.tabIndex, TextField.type; Chapter 10


Table of Contents