Example
The following example loads styles from a CSS file, parses the stylesheet and writes style names
and property values to the log file. Create a new ActionScript file called StyleSheetTracer.as and
enter the following code:
import TextField.StyleSheet;
class StyleSheetTracer {
// StyleSheetTracer.displayFromURL
//
// This method displays the CSS style sheet at
// URL "url" to the Output Panel.
static function displayFromURL(url:String):Void {
// Create a new style sheet object
var my_styleSheet:StyleSheet = new StyleSheet();
// The load operation is asynchronous, so set up
// a callback function to display the loaded style sheet.
my_styleSheet.onLoad = function(success:Boolean) {
if (success) {
StyleSheetTracer.display(this);
} else {
trace("Error loading style sheet "+url);
}
};
// Start the loading operation.
my_styleSheet.load(url);
}
static function display(my_styleSheet:StyleSheet):Void {
var styleNames:Array = my_styleSheet.getStyleNames();
if (!styleNames.length) {
trace("This is an empty style sheet.");
} else {
for (var i = 0; i<styleNames.length; i++) {
var styleName:String = styleNames[i];
trace("Style "+styleName+":");
var styleObject:Object = my_styleSheet.getStyle(styleName);
for (var propName in styleObject) {
var propValue = styleObject[propName];
trace("\t"+propName+": "+propValue);
}
trace("");
}
}
}
}
Create a new CSS document called styles.css, which has two styles called
that define properties for
/* In styles.css */
.heading {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
font-weight: bold;
}
.mainBody {
768
Chapter 7: ActionScript for Flash
,
font-family
font-size
heading
and
. Enter the following code:
font-weight
and
mainBody
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?