Specifications

CHAPTER 4
78
StyleManager.getStyleDeclaration("Button").setStyle("color", 0x00CCFF);
}
]]></mx:Script>
<mx:Panel id="panel1">
<mx:Button id="b1" label="Click Me"/>
<mx:Button id="b2" label="Click Me"/>
<mx:Button id="b3" label="Click Me"/>
</mx:Panel>
</mx:Application>
If possible, set global styles at authoring time by using CSS. If you must set them at run time, try to set styles by
using the techniques described in Reducing calls to the setStyle() method” on page 76.
Calling the setStyleDeclaration() and loadStyleDeclarations() methods
The setStyleDeclaration() method is computationally expensive. You can prevent Flash Player from applying
or clearing the new styles immediately by setting the
update parameter to false.
The following example sets new class selectors on different targets, but does not trigger the update until the last
style declaration is applied:
<?xml version="1.0"?>
<!-- styles/SetStyleDeclarationExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script><![CDATA[
import mx.styles.StyleManager;
private var myButtonStyle:CSSStyleDeclaration = new
CSSStyleDeclaration('myButtonStyle');
private var myLabelStyle:CSSStyleDeclaration = new
CSSStyleDeclaration('myLabelStyle');
private var myTextAreaStyle:CSSStyleDeclaration = new
CSSStyleDeclaration('myTextAreaStyle');
private function initApp():void {
myButtonStyle.setStyle('color', 'blue');
myLabelStyle.setStyle('color', 'blue');
myTextAreaStyle.setStyle('color', 'blue');
}
private function applyStyles():void {
StyleManager.setStyleDeclaration("Button", myButtonStyle, false);
StyleManager.setStyleDeclaration("Label", myLabelStyle, false);
StyleManager.setStyleDeclaration("TextArea", myTextAreaStyle, true);
}