422 Working with Text and Strings
You can create styles that redefine built-in HTML formatting tags that Flash Player uses (such
as
<p> and <li>). You can also create style classes that can be applied to specific HTML
elements using the
<p> or <span> tag’s class attribute, or define new tags.
You use the TextField.StyleSheet class to work with text style sheets. Although the TextField
class can be used with Flash Player 6, the TextField.StyleSheet class requires that SWF files
target Flash Player 7 or later. You can load styles from an external CSS file or create them
natively using ActionScript. To apply a style sheet to a text field that contains HTML- or
XML-formatted text, you use the
TextField.styleSheet property. The styles defined in the
style sheet are mapped automatically to the tags defined in the HTML or XML document.
Using styles sheets involves the following three basic steps:
■ Create a style sheet object from the TextField.StyleSheet class (for more information see
StyleSheet (TextField.StyleSheet) in the ActionScript 2.0 Language Reference).
■ Add styles to the style sheet object, either by loading them from an external CSS file or by
creating new styles with ActionScript.
■ Assign the style sheet to a TextField object that contains HTML- or XML-formatted text.
For more information, see the following topics:
■ “Supported CSS properties” on page 423
■ “Creating a style sheet object” on page 424
■ “Loading external CSS files” on page 424
■ “Creating new styles with ActionScript” on page 426
■ “Applying styles to a TextField object” on page 427
■ “Applying a style sheet to a TextArea component” on page 427
■ “Combining styles” on page 429
■ “Using style classes” on page 429
■ “Styling built-in HTML tags” on page 430
■ “An example of using styles with HTML” on page 431
■ “Using styles to define new tags” on page 433
■ “An example of using styles with XML” on page 434
You can find a sample source file, formattedText.fla, in the Samples folder on your hard disk,
which shows you how to apply CSS formatting to text that you load into a SWF file
at runtime.
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\LoadText.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples and
Tutorials/Samples/ActionScript/LoadText.