ActionScript 2.0 Language Reference |
|
|
|
| ActionScript classes > TextField > replaceText (TextField.replaceText method) | |||
Replaces a range of characters, specified by the beginIndex and endIndex parameters, in the specified text field with the contents of the newText parameter.
Note: This method will not work if a style sheet is applied to the text field.
Availability: ActionScript 1.0; Flash Player 7
beginIndex:Number - The start index value for the replacement range.
endIndex:Number - The end index value for the replacement range.
newText:String - The text to use to replace the specified range of characters.
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.");
}
If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth() method, which is used in this example.
|
|
|
|