User Guide

866 Chapter 2: ActionScript Language Reference
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. For more information, see “Creating subclasses” in Using
ActionScript in Flash.
Example
The following example parses the CSS in css_str. The ActionScript displays information about
whether it parsed successfully, and then displays the parsed CSS in the Output panel. 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");
}
//
function dumpStyles(styles:TextField.StyleSheet):Void {
var styleNames_array:Array = styles.getStyleNames();
for (var i = 0; i<styleNames_array.length; i++) {
var styleName_str:String = styleNames_array[i];
var styleObject:Object = styles.getStyle(styleName_str);
trace(styleName_str);
for (var prop in styleObject) {
trace("\t"+prop+": "+styleObject[prop]);
}
trace("");
}
}