User Guide
772 Chapter 7: ActionScript for Flash
news_txt.htmlText = "<p class=\"heading\">Heading goes here!</p><p
class=\"mainBody\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.</p>";
}
};
my_styleSheet.load("styles.css");
For the code contained in styles.css, see the entry for TextField.StyleSheet.getStyle(). For
an example of asynchronously loading style sheets using ActionScript 2.0, see the entry for
TextField.StyleSheet.getStyle().
See also
TextField.StyleSheet.load()
TextField.StyleSheet.parseCSS()
Availability
Flash Player 7.
Usage
styleSheet.parseCSS(cssText:String) : Boolean
Parameters
cssText
The CSS text to parse (a string).
Returns
A Boolean value indicating if the text was parsed successfully (true) or not (false).
Description
Method; parses the CSS in cssText and loads the style sheet with it. If a style in cssText is
already in
styleSheet, the properties in styleSheet are retained, and only the ones in cssText
are added or changed in
styleSheet.
To extend the native CSS parsing capability, you can override this method by creating a subclass
of the TextField.StyleSheet class.
Example
The following example parses the CSS in css_str. The ActionScript writes information about
whether it parsed successfully, and then writes the parsed CSS in the log file. Add the following
ActionScript to your AS or FLA file:
var css_str:String = ".heading {font-family: Arial, Helvetica, sans-serif;
font-size: 24px; font-weight: bold; }";
var my_styleSheet:TextField.StyleSheet = new TextField.StyleSheet();
if (my_styleSheet.parseCSS(css_str)) {
trace("parsed successfully");
dumpStyles(my_styleSheet);
} else {
trace("unable to parse CSS");
}