setSelection (Selection.setSelection method)

public static setSelection(beginIndex:Number, endIndex:Number) : Void

Sets the selection span of the currently focused text field. The new selection span will begin at the index specified in the beginIndex parameter, and end at the index specified in the endIndex parameter. Selection span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on). This method has no effect if there is no currently focused text field.

Availability: ActionScript 1.0; Flash Player 5

Parameters

beginIndex:Number - The beginning index of the selection span.

endIndex:Number - The ending index of the selection span.

Example

In the following ActionScript, you create a text field at runtime and add a string to it. Then you focus the text field and select a span of characters in the focused text field.

this.createTextField("myText_txt", 99, 10, 10, 200, 30);
myText_txt.text = "this is my text";
this.onEnterFrame = function () {
    Selection.setFocus("myText_txt");
    Selection.setSelection(0, 3);
    delete this.onEnterFrame;
}

The following example illustrates how the endIndex parameter is not inclusive. In order to select the first character, you must use an endIndex of 1, not 0. If you change the endIndex parameter to 0, nothing will be selected.

this.createTextField("myText_txt", 99, 10, 10, 200, 30);
myText_txt.text = "this is my text";
this.onEnterFrame = function () {
    Selection.setFocus("myText_txt");
    Selection.setSelection(0, 1);
    delete this.onEnterFrame;
}