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( )
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.