Name
Selection.getFocus( ) Method — identify the text field in which the cursor currently resides
Availability
Flash 5
Synopsis
Selection.getFocus( )
Returns
A string indicating the full path to the
text field variable that has keyboard focus (i.e., the one in which
the cursor currently resides), for example,
"_level1.myTextField". If no text field has
keyboard focus, it returns null.
Description
The getFocus( ) method identifies which text
field currently has focus (if any) by returning its string path. To
turn that string into a variable reference, we use eval(
). For example, in the following code we identify the
number of characters in the text field with focus. We retrieve the
name of the field by invoking getFocus( ), and
we convert that name into a variable with eval(
) :
var numChars = eval(Selection.getFocus( )).length;
Example
Because getFocus( ) returns
null when no text field is selected, we may
determine whether any field has focus by checking whether
getFocus( ) is equal to null,
as follows:
if (Selection.getFocus( ) == null) {
trace("No field has focus");
}See Also
Selection.setFocus( ), eval(
), Selection.getCaretIndex( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access