Recipe 9.29. Replacing Text


Problem

You want to replace text.

Solution

Use the replaceSelectedText( ) method to replace the highlighted text and replaceText( ) to replace a range of text.

Discussion

The replaceSelectedText( ) method enables you to replace the selected text in a text field. Simply pass the method the string to use as the replacement text. For the method to work, the text field must have focus:

_field.replaceSelectedText("new text");

Use the replaceText( ) method to replace text within a text string given a starting and ending index. The following replaces the text from index 100 to index 150, with the new string specified by the third parameter:

_field.replaceText(100, 150, "new text");




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

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