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( )
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