Adobe Flex 3 Help

Basics of working with text

Introduction to working with text

To display any text on the screen in Adobe Flash Player or Adobe® AIR™, 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 Flex text components please see "About text controls" in the Flex Developer's Guide.

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.

Common tasks for working with text

The following common text-related tasks are described in this chapter:

  • Modifying text field contents
  • Using HTML in text fields
  • Using images in text fields
  • Selecting text and working with user-selected text
  • Capturing text input
  • Restricting text input
  • Applying formatting and CSS styles to text
  • Fine-tuning text display with sharpness, thickness, and anti-aliasing
  • Accessing and working with static text fields from ActionScript

Important concepts and terms

The following reference list contains important terms that you will encounter in this chapter:

  • Cascading style sheets: A standard syntax for specifying styles and formatting for content that's structured in XML (or HTML) format.
  • Device font: A font that is installed on the user's machine.
  • Dynamic text field: A text field whose contents can be changed by ActionScript but not by user input.
  • Embedded font: A font that has data its character outline data stored in the application's SWF file.
  • HTML text: Text content entered into a text field using ActionScript that includes HTML formatting tags along with actual text content.
  • Input text field: A text field whose contents can be changed either by user input or by ActionScript.
  • Static text field: A text field created in the Flash authoring tool, whose content cannot change when the SWF file is running.
  • Text line metrics: Measurements of the size of various parts of the text content in a text field, such as the baseline of the text, the height of the top of the characters, size of descenders (the part of some lowercase letters that extends below the baseline), and so on.