Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Working with text > Basics of working with text | |||
To display any text on the screen in Adobe Flash Player, you use an instance of the TextField class. The TextField class is the basis for other text-based components, like the TextArea components or the TextInput components, that are provided in the Adobe Flex framework and in the Flash authoring environment. For more information about using text components in the Flash authoring environment, please see "About text controls" in Using Flash.
Text field content can be pre-specified in the SWF file, loaded from an external source like a text file or database, or entered by users interacting with your application. Within a text field, the text can appear as rendered HTML content, with images embedded in the rendered HTML. Once you establish an instance of a text field, you can use flash.text package classes, like the TextFormat class and the StyleSheet class, to control the text's appearance. The flash.text package contains nearly all the classes related to creating, managing, and formatting text in ActionScript.
You can format text by defining the formatting with a TextFormat object and assigning that object to the text field. If your text field contains HTML text, you can apply a StyleSheet object to the text field to assign styles to specific pieces of the text field content. The TextFormat object or StyleSheet object contains properties defining the appearance of the text, such as color, size, and weight. The TextFormat object assigns the properties to all the content within a text field or to a range of text. For example, within the same text field, one sentence can be bold red text and the next sentence can be blue italic text.
For more information on text formats, see Assigning text formats.
For more information on HTML text in text fields, see Displaying HTML text.
For more information on style sheets, see Applying cascading style sheets.
In addition to the classes in the flash.text package, you can use the flash.events.TextEvent class to respond to user actions related to text.
The following common text-related tasks are described in this chapter:
The following reference list contains important terms that you will encounter in this chapter:
As you're working through the chapter, you may want to test some of the example code listings for yourself. Because this chapter is about working with text fields in ActionScript, essentially all the code listings in this chapter involve manipulating a TextField object, either one that has been created and placed on the Stage in the Flash authoring tool, or one that's created using ActionScript. Testing a sample involves viewing the result in Flash Player to see the effects of the code on the text field.
The examples in this chapter fall into two groups. One type of example manipulates a TextField object without creating the object explicitly. To test these code listings in this chapter:
myTextField, you should name your text field myTextField as well.On the screen you will see the results of the code manipulating the text field as specified in the code listing.
The other type of example code listing in this chapter consists of a class definition that is intended to be used as the document class for the SWF. In those listings, a TextField instance is created by the example code, so you will not need to create one separately. To test this type of code listing:
You will see the results of the example displayed on the screen.
Other techniques for testing example code listings are explained in more detail in Testing in-chapter example code listings.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000219.html