User Guide

Using styles to customize component color and text 89
You can also access styles on the custom style declaration using the setStyle() and
getStyle() methods through the declarations global styleName property. For example, the
following code sets the
backgroundColor style on the myStyle style declaration:
_global.styles.myStyle.setStyle("themeColor", "haloOrange");
However, steps 5 and 6 associated the new_style instance with the style declaration so you
can use the shorter syntax, like
new_style.setStyle("themeColor", "haloOrange").
For more information about the
setStyle() and getStyle() methods, see
UIObject.setStyle() and UIObject.getStyle().
Setting styles for a component class
You can define a class style declaration for any class of component (Button, CheckBox, and so
on) that sets default styles for each instance of that class. You must create the style declaration
before you create the instances. Some components, such as TextArea and TextInput, have class
style declarations predefined by default because their
borderStyle and backgroundColor
properties must be customized.
The following code first checks to see if the current theme already has a style declaration for
CheckBox, and, if not, creates a new one. Then the code uses the
setStyle() method to
define a style property for the CheckBox style declaration (in this case, “color” sets the color
for all check box label text to blue):
if (_global.styles.CheckBox == undefined) {
_global.styles.CheckBox = new mx.styles.CSSStyleDeclaration();
}
_global.styles.CheckBox.setStyle("color", 0x0000FF);
For a table of the style properties you can set on the CheckBox component, see “Using styles
with the CheckBox component” in the Components Language Reference.
Custom style settings have priority over inherited and global style settings. For a list of style
precedence, see “Using global, custom, and class styles in the same document” on page 92.
CAUTION
If you replace a class style sheet, make sure to add any styles that you want from the old
style sheet; otherwise, they will be overwritten.