User Guide
Formatting text with Cascading Style Sheets 231
myTextArea.html = true;
var myVars:LoadVars = new LoadVars();
//var styles = new TextField.StyleSheet();
// Load text to display and define onLoad handler
myVars.load("myText.htm");
myVars.onData = function(content) {
_root.myTextArea.text = content;
};
Combining styles
CSS styles in Flash Player are additive; that is, when styles are nested, each level of nesting can
contribute style information, which is added together to result in the final formatting.
The following example shows some XML data assigned to a text field:
<sectionHeading>This is a section</sectionHeading>
<mainBody>This is some main body text, with one
<emphasized>emphatic</emphasized> word.</mainBody>
For the word emphatic in the above text, the emphasized style is nested within the mainBody
style. The
mainBody style contributes color, font-size, and decoration rules. The emphasized
style adds a font-weight rule to these rules. The word emphatic will be formatted using a
combination of the rules specified by
mainBody and emphasized.
Using style classes
You can create style “classes” (not true ActionScript 2.0 classes) that you can apply to a
<p> or
<span> tag using either tag’s class attribute. When applied to a <p> tag, the style affects the
entire paragraph. You can also style a span of text that uses a style class using the
<span> tag.
For example, the following style sheet defines two styles classes:
mainBody and emphasis:
.mainBody {
font-family: Arial,Helvetica,sans-serif;
font-size: 24px;
}
.emphasis {
color: #666666;
font-style: italic;
}
Within HTML text you assign to a text field, you can apply these styles to <p> and <span> tags,
as shown in the following example:
<p class='mainBody'>This is <span class='emphasis'>really exciting!</span></p>
Styling built-in HTML tags
Flash Player supports a subset of HTML tags. (For more information, see “Using HTML-
formatted text” on page 236.) You can assign a CSS style to every instance of a built-in HTML
tag that appears in a text field. For example, the following code defines a style for the built-in
<p>
HTML tag. All instances of that tag are styled in the manner specified by the style rule.