Chapter 15. Working with Text and Fonts

Introduction

In this chapter

  • Introducing TextFields

  • Using TextFormat objects

  • Creating input fields

  • Listening to TextField events

Text is an indispensable aspect of any web application and the TextField is the base object for dealing with text anywhere in Flash Player 9. It handles both text fields that a user can put text into, like a form, or it can display text simply by setting its type to either input or dynamic. We discuss these types later on, but for right now, just understand that a TextField is still a TextField if it's taking user input or just displaying some text.

To display our TextField objects, we'll add and remove them from the stage or parent object like any other DisplayObject. Because TextField extends flash.display.InteractiveObject, it has methods to deal with mouse interaction, many interactive events it can throw, as well as many of the methods we are familiar with from Chapter 13. Sizing, scaling, moving, and reparenting a TextField is all handled in the same way as any other DisplayObject, which shortens the learning curve.

Unique to the TextField are methods and properties to control the appearance of text within it with TextFormat objects or CSS styles or with a subset of HTML. Using the TextFormat class, we can set properties for the entire TextField or just for certain groups of characters within the TextField. We put this to good use for handling user selections of characters. We'll also look at how to embed system fonts ...

Get ActionScript™ 3.0 Bible 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.