Table of Contents

Selection.getBeginIndex( ) Method Flash 5

retrieve the index of the first selected character in the text field with keyboard focus
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();
// eval( ) is required because Selection.getFocus( ) returns a string
var currentSelection =
    eval(Selection.getFocus()).text.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( ), TextField.replaceSel( )


Table of Contents