Chapter 9. Text
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:
createTextField();
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 ...
Get ActionScript 3.0 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.