Name

Selection.setSelection( ) Method — select characters in the text field with focus, or set the insertion point

Availability

Flash 5

Synopsis

Selection.setSelection(beginIndex, endIndex)

Arguments

beginIndex

A non-negative integer specifying the index of the first character to be included in the new selection.

endIndex

A non-negative integer specifying the index of the character after the last character to be included in the new selection.

Description

The setSelection( ) method selects (highlights) the characters from beginIndex to endIndex- 1 in the text field with focus. If no field has focus, setSelection( ) has no effect. It is commonly used to highlight problematic user input.

Usage

Though the Selection object does not have a "setCaretIndex" method, we may use the setSelection( ) method to set the insertion point to a specific location within a text field. To do so, we specify the same beginIndex and endIndex values, as in:

// Set the insertion point after the third character
Selection.setSelection(3, 3);

Example

// Select the second and third letters
// of the currently focused text field
Selection.setSelection(1, 3);

See Also

Selection.getBeginIndex( ), Selection.getCaretIndex( ), Selection.getEndIndex( )

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.