Recipe 8.25 Setting the Insertion Point in a Text Field

8.25.1 Problem

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

8.25.2 Solution

Use the Selection.setSelection( ) method, specifying the same value for the starting and ending indexes.

8.25.3 Discussion

You can use Selection.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 that has focus:

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

8.25.4 See Also

Recipe 8.24



ActionScript Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2005
Pages: 425

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