User Guide

1152 ActionScript classes
Parameters
name:String - The name of the style to add to the StyleSheet.
style:Object - An object that describes the style, or null.
Example
The following example adds a style named
emphasized to the StyleSheet myStyleSheet. The
style includes two style properties:
color and fontWeight. The style object is defined with
the
{} operator.
myStyleSheet.setStyle("emphasized", {color:'#000000',fontWeight:'bold'});
You could also create a style object using an instance of the Object class, and then pass that
object (
styleObj) as the style parameter, as the next example shows:
import TextField.StyleSheet;
var my_styleSheet:StyleSheet = new StyleSheet();
var styleObj:Object = new Object();
styleObj.color = "#000000";
styleObj.fontWeight = "bold";
my_styleSheet.setStyle("emphasized", styleObj);
delete styleObj;
var styleNames_array:Array = my_styleSheet.getStyleNames();
for (var i=0;i<styleNames_array.length;i++) {
var styleName:String = styleNames_array[i];
var thisStyle:Object = my_styleSheet.getStyle(styleName);
trace(styleName);
for (var prop in thisStyle) {
trace("\t"+prop+": "+thisStyle[prop]);
}
trace("");
}
The following information appears in the Output panel:
emphasized
fontWeight: bold
color: #000000
See also
{} object initializer operator, StyleSheet (TextField.StyleSheet)
NOTE
Because Flash Player creates a copy of the style object you pass to setStyle(), the
delete styleObj command in the code example reduces memory usage by deleting the
original style object passed to
setStyle().