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( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access