Chapter 8. Text

Introduction

Flash MX introduces a rich ActionScript API for working with text in movies. Prior versions didn’t allow much more than being able to control the value displayed in manually created text fields.

The TextField class is used to create and manipulate text at runtime (though the text itself can be created either at runtime or authoring time). Through methods and properties of a text field you can alter text visibility, change the position of the text within the movie, enable user input, and much more. In addition, there are two “helper” classes—TextFormat and Selection—that play a supporting role. TextFormat objects are used to apply formatting options such as font, font size, indentation, and margins to text fields. The Selection object allows programmatic control over keyboard focus and is helpful for selecting and deselecting text fields and the text within them.

Text fields share similar properties with MovieClip and Button objects to control an object’s position, rotation, and visibility, plus others shown in Table 8-1 (for a complete list of TextField properties, refer to the online help under Help ActionScript Dictionary).

Table 8-1. TextField graphical display properties

Property

Description

_x

x coordinate of the text field relative to its parent

_y

y coordinate of the text field relative to its parent

_width

Width of the text field in pixels

_height

Height of the text field in pixels

_xscale

Horizontal scale of the text ...

Get Actionscript 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.