Selection.getCaretIndex( ) Method

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

retrieve the index of the insertion point in a text field
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 a text field. The cursor appears as an I-beam when a text field has keyboard focus. Use setSelection( ) to set the location of the insertion point.

Example

Because getCaretIndex( ) returns -1 when no text field has focus, we can determine whether any field has focus by checking whether getCaretIndex( ) is equal to -1

The following example checks whether any text field has keyboard focus:

if (Selection.getCaretIndex() =  = -1) {   trace("No field has focus"); }

Reader Exercise: Rewrite the preceding example as a Boolean function, isTextFieldActive( ), which returns true if a text field has focus and returns false otherwise. Modify it to accept an optional text field identifier and check whether that specific text field is active. (Hint: See Selection.getFocus( )).

See Also

Selection.getFocus( ), Selection.setSelection( )



    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