
TextField.replaceSel() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
860
|
ActionScript Language Reference
// Then sometime later...delete the text field
theField_txt.removeTextField();
See Also
MovieClip.createTextField(), MovieClip.removeMovieClip()
TextField.replaceSel() Method
replace selected text (without disturbing formatting)
Flash 6
theField.replaceSel(newText)
Arguments
newText The string of new characters that will replace the current selection.
Description
The replaceSel() method deletes the selected characters in theField and replaces them with
newText. If no characters are selected in theField, replaceSel() simply inserts newText at
theField’s insertion point, or before the first character if theField is not focused. The new
amalgamated value is reflected by
theField.text.
While replaceSel()’s use may seem limited, it is actually one of the most important
TextField methods because it provides the only means of inserting new text into a text field
without disturbing existing character formatting. To update a text field’s value using
replaceSel(), we must first focus the field, then position the insertion point, and then insert
the text, as follows:
// Focus the field
Selection.setFocus("theField_txt");
// Position insertion point after the fourth character
Selection.setSelection(4, 4);
// Insert new text
theField_txt.replaceSel("text ...