Setting styles for a component class

The docs say that this can be used to set a global style for a particular component:

_global.styles.RadioButton.setStyle("color", "blue");

What’s not quite clear from this is that before doing that, you’d need to create the style object for the RadioButton class first:

_global.styles.RadioButton = new mx.styles.CSSStyleDeclaration();

Otherwise you’re calling setStyle on a null reference.

Also interesting to note is the fact that setStyle is not actually a method of CSSStyleDeclaration. I don’t know where it comes from, actually (UIObject? Some kind of mixin?). Therefore you can’t use strict typing on style objects if you’re going to call setStyle on them.

Update: Got some more information on this from a response on FlashCoders. Turns out that setStyle does indeed come from a mixin — in short, UIComponent loads in UIComponentExtensions, which calls mx.styles.CSSSetStyle.enableRunTimeCSS(), which in turn causes the CSSSetStyle methods to be mixed in to CSSStyleDeclaration.

Leave a Reply