
TextField.textColor Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
874
|
ActionScript Language Reference
Text can be formatted via the setTextFormat() and setNewTextFormat() methods.
However, reassigning the
text property clears all previous formatting. To add text to a field
without disturbing any existing formatting, use replaceSel().
See
TextField.htmlText for a full discussion of assigning HTML-formatted text to a text
field. Take heed that
htmlText and text overwrite each other. Regardless of the value of the
html property, assigning a value to text overwrites the value of htmlText, and vice versa.
Usage
In Flash 4 and Flash 5, text fields were represented by simple variables, not complete
objects. Hence, it was common to assign text directly to a text field variable, as follows:
theField_txt = "Welcome to my site.";
As of Flash 6, this practice will erroneously overwrite the TextField instance. The correct
syntax in Flash 6 is as follows:
theField_txt.text = "Welcome to my site.";
See TextField.variable for details.
Example
The text property is our main means of programmatically displaying text on screen. It’s
Flash’s best candidate for a “hello world” example, as follows:
// Create a text field
this.createTextField("theField_txt", 1, 0, 0, 200, 20);
// Drum roll please...
theField_txt.text = "hello world!";
The following code ...