O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.25. Setting the Insertion Point in a Text Field

Problem

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

Solution

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

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);

See Also

Recipe 8.24

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required