Name

Selection.getCaretIndex( ) Method — retrieve the index of the insertion point

Availability

Flash 5

Synopsis

Selection.getCaretIndex( )

Returns

The index of the insertion point in the current text field. If no text field has keyboard focus, it returns -1. If the text field with focus is empty, it returns 0.

Description

The getCaretIndex( ) method indicates the insertion point (i.e., the location of the cursor) in a text field. The cursor appears as an I-beam when a text field has keyboard focus. Use setSelection( ) to set the location of the insertion point.

Example

Because getCaretIndex( ) returns -1 when no text field has focus, we may determine whether any field has focus by checking whether getCaretIndex( ) is equal to -1, as follows:

if (Selection.getCaretIndex( ) == -1) {
  trace("No field has focus");
}

See Also

Selection.setSelection( )

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.