Formatting Characters and Paragraphs
Formatting text is such a noble endeavor that ActionScript devotes an entire class to the job. Once you learn the ins and outs of the TextFormat class, you can do it all. It works the same for TLF and Classic text and all the text types they encompass. You can apply a single format to an entire text field and then fine-tune specific words or phrases with special formatting like bold, italic, or color highlights. Some formatting properties you apply to specific characters, while others you apply to entire paragraphs.
Most of the action takes place using the properties of the TextFormat class. As you'd expect, the TextFormat class has character-level properties that set font names, size, style, and color. It also includes paragraph-level properties that control the alignment, margins, indents, kerning, leading (line spacing), and bullets.
TextFormat is an object itself, so you need to create an instance of the TextFormat class to use in your program. Here's an example of code that does that:
var txtFormat:TextFormat = new TextFormat();
The next step is to choose the format options you want to include in this specific instance of the class. For example, you can choose the typeface and font size using the TextFormat's properties:
txtFormat.font = "Cooper Black"; txtFormat.size = 20; txtFormat.align = "center";
As explained earlier, when you use ActionScript to create text fields, you need to choose fonts that you know are on your audience's computers, ...
Get Flash CS5: The Missing Manual 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.