9.0.
Introduction
The
flash.text.TextField
class is the way in which all text is displayed in Flash Player.
Even the text components such as TextArea and
TextInput use the TextField class to display text.
Flash Player enables a great deal of functionality for text fields
from enabling user input to embedding fonts to using Cascading
Style Sheets (CSS) to format text. In this chapter, we'll discuss
all the many things you can accomplish with text.
As implied in the preceding paragraph, the
TextField class is packaged in the flash.display package. Therefore,
you need to either import the class or refer to the class with the
fully qualified class name. All examples in this chapter assume
you've imported the class with the following line of code:
import flash.text.TextField;
ActionScript 3.0 uses a display list that is
quite different from previous versions of ActionScript. With
earlier versions of ActionScript, you construct a text field using
the TextField constructor as follows:
var field:TextField = new TextField( );
However, with ActionScript 3.0, the new text
field object isn't automatically added to the display list. That
means that if you want to make the text field visible, you have to
use the addChild( )
method. As discussed in Chapter 6,
the addChild( ) method is defined for all container display
objects, such as Sprite, and it adds the object specified as
a parameter to the display list of the object from which it is
called. For example, the following line of code adds the field
TextField object to the display list of the instance of the
TextExample class:
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextExample extends Sprite {
public function TextExample( ) {
var field:TextField = new TextField( );
addChild(field);
}
}
}
When the examples in this chapter reference an
object called field, it's frequently assumed that the
object is a TextField object that was instantiated via the
TextField constructor and added to the display list with the
addChild( ) method.
|