Once a text field's text content has been set, it can be
reassigned via the
For example, the following code creates a TextField object and sets it text content
var t:TextField = new TextField(); t.text = "Hello";
The following code completely reassigns
t's text to the string "Goodbye":
t.text = "Goodbye";
To add new text following a text field's existing text (rather
than completely reassigning the text field's text), we use either the
TextField class's instance method
appendText( ) or the
+= operator. For example, the following code
adds the string "...hope to see you again!" to the text
t.appendText("...hope to see you again!");
After the preceding line of code executes,
t.text has the value:
"Goodbye...hope to see you again!"
The appended text adopts the formatting of the last character in the text field, and any existing text retains its original formatting. If the text field contains no text when appendText( ) is called, the appended text is formatted with the text field's default text format.
For information on text formatting and the default text format, see the next section, "Formatting Text Fields."
Like the preceding code, the following code adds new text at the
end of a text field's existing text, but does so with the
+= operator rather than appendText( ):
t.text += " Come again soon.";
Unlike appendText( ), the
+= operator resets the formatting
of all text in the text field to the default text format. The ...