Table of Contents

Selection.setSelection( ) Method Flash 5

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

Arguments

beginIndex

A nonnegative integer specifying the index of the first character to be included in the new selection.

endIndex

A nonnegative 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 commonly is used to highlight problematic user input. To replace the text in the current selection, use TextField.replaceSel( ).

Usage

Though the Selection object does not have a "setCaretIndex" method, we can 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( ), TextField.replaceSel( )


Table of Contents