Specifications

77ADOBE FLEX 3
Building and Deploying Adobe Flex 3 Applications
Some applications must call the setStyle() method during the application or object instantiation. If this is the
case, call the
setStyle() method early in the instantiation phase. Early in the instantiation phase means setting
styles from the component or applications
preinitialize event, instead of the initialize or
creationComplete event. By setting the styles as early as possible during initialization, you avoid unnecessary
style notification and lookup.
If you programmatically create a component and want to set styles on that component, call the
setStyle()
method before you attach it to the display list with a call to the
addChild() method, as the following example
shows:
<?xml version="1.0"?>
<!-- optimize/CreateStyledButton.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp(event)">
<mx:Script><![CDATA[
import mx.controls.Button;
public function initApp(e:Event):void {
var b:Button = new Button();
b.label="Click Me";
b.setStyle("color", 0x00CCFF);
panel1.addChild(b);
}
]]></mx:Script>
<mx:Panel id="panel1"/>
</mx:Application>
Setting global styles
Changing global styles (changing a CSS ruleset that is associated with a class or type selector) at run time is an
expensive operation. Any time you change a global style, Flash Player must perform the following actions:
Traverse the entire application looking for instances of that control.
Check all the controls children if the style is inheriting.
Redraw that control.
The following example globally changes the Button controls color style property:
<?xml version="1.0"?>
<!-- optimize/ApplyGlobalStyles.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp(event)">
<mx:Script><![CDATA[
public function initApp(e:Event):void {