
Selection.getCaretIndex() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
749
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()
Selection.getCaretIndex() Method
retrieve the index of the insertion point in a text field
Flash 5
Selection.getCaretIndex()
Returns
The index of the insertion point in the currently focused text field. If no text field has
keyboard focus, it returns –1. If the text field with focus is empty, it returns 0.
Description
The getCaretIndex() method indicates the insertion point (i.e., the location of the cursor) in ...