Selection.setSelection( ) Method | Flash 5 |
select characters in the text field with focus, or set the insertion point |
A nonnegative integer specifying the index of the first character to be included in the new selection.
A nonnegative integer specifying the index of the character after the last character to be included in the new selection.
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( ).
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);
// Select the second and third letters of the currently focused text field Selection.setSelection(1, 3);
Selection.getBeginIndex( ), Selection.getCaretIndex( ), Selection.getEndIndex( ), TextField.replaceSel( )