User Guide

912 Chapter 2: ActionScript Language Reference
TextField.replaceText()
Availability
Flash Player 7.
Usage
my_txt.replaceText(beginIndex:Number, endIndex:Number, text:String) : Void
Description
Method; replaces a range of characters, specified by the beginIndex and endIndex parameters, in
the specified text field with the contents of the
text parameter.
Example
The following example creates a text field called my_txt and assigns the text dog@house.net to
the field. The
indexOf() method is used to find the first occurrence of the specified symbol (@).
If the symbol is found, the specified text (between the index of 0 and the symbol) replaces with
the string
bird. If the symbol is not found, an error message is displayed in the Output panel.
this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 22);
my_txt.autoSize = true;
my_txt.text = "dog@house.net";
var symbol:String = "@";
var symbolPos:Number = my_txt.text.indexOf(symbol);
if (symbolPos>-1) {
my_txt.replaceText(0, symbolPos, "bird");
} else {
trace("symbol '"+symbol+"' not found.");
}