Table of Contents

Selection.getFocus( ) Method Flash 5; enhanced in Flash 6 to support buttons and movie clips

identify the currently focused button, movie clip, or text field
Selection.getFocus()

Returns

A string indicating the full path to the object that has keyboard focus (for example, "_level1.theField_txt" or "_level0.listBox_mc"). If no button, movie clip, or text field currently has keyboard focus, it returns null.

Description

The getFocus( ) method identifies which button, movie clip, or text field (if any) currently has input focus by returning its string path. To turn that string into an object reference, we use eval( ). In the following example, we retrieve the instance name of the focused field using getFocus( ), and we convert that name into an object reference using eval( ). We then count the number of characters in the text field (not just the length of the selection) :

var numChars = eval(Selection.getFocus()).text.length;

Example

Because getFocus( ) returns null when no object is selected, we can determine whether any object has focus by checking whether getFocus( ) is equal to null, as follows:

if (Selection.getFocus() =  = null) {
  trace("No button, movie clip, or text field has focus");
}

See Also

eval( ), Selection.getCaretIndex( ), Selection.setFocus( )


Table of Contents