Selection.setSelection( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Selection.setSelection( ) Method Flash 5

select characters in the text field with focus, or set the insertion point
Selection.setSelection(beginIndex, endIndex)

Arguments

beginIndex

A nonnegative integer specifying the index of the first character to be included in the new selection.

endIndex

A nonnegative 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 commonly is used to highlight problematic user input. To replace the text in the current selection, use TextField.replaceSel( ).

Usage

Though the Selection object does not have a "setCaretIndex" method, we can 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( ), TextField.replaceSel( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net