Name
Selection.getBeginIndex( ) Method — retrieve the index of a text field’s first selected character
Availability
Flash 5
Synopsis
Selection.getBeginIndex( )
Returns
The index of the first character in the current selection
(highlighted block of text). If no text field has keyboard focus, it
returns -1. If a text field has focus but no characters are selected,
it returns the value of Selection.getCaretIndex(
)
.
Description
The getBeginIndex( )
method identifies the
beginning of a selection. To determine the span of characters
currently selected, use both getBeginIndex( )
and getEndIndex( )
.
Example
The following example creates a string representing the currently selected characters and then displays that string in the Output window:
var firstChar = Selection.getBeginIndex( ); var lastChar = Selection.getEndIndex( ); var currentSelection = eval(Selection.getFocus( )).substring(firstChar, lastChar); trace(currentSelection);
The following code extends the current selection by one character to the left:
Selection.setSelection(Selection.getBeginIndex() - 1, Selection.getEndIndex( ));
See Also
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.