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.

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.

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 ActionScript 2.0 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.