Recipe 9.22. Setting the Insertion Point in a Text Field


Problem

You want ActionScript to set the insertion point for a text field.

Solution

Use the TextField.setSelection( ) method.

Discussion

You can use TextField.setSelection( ) to set the cursor position in a text field by setting the beginning and ending index parameters to the same value. This example sets the cursor position in the text field, assuming it has focus:

// Positions the insertion point before the first character field.setSelection(0, 0);

You can retrieve the index of the cursor position with the read-only caretIndex property:

trace(field.caretIndex);

See Also

Recipe 9.21




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

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