+展开-ActionScript
var vboxStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
vboxStyle.setStyle( "backgroundColor", 0xFF0000 );
StyleManager.setStyleDeclaration( "VBox", vboxStyle, false );
+展开-ActionScript
var redBoxStyle:CSSStyleDeclaration = new CSSStyleDeclaration();
redBoxStyle.setStyle( "backgroundColor", 0xFF0000 );
StyleManager.setStyleDeclaration( ".redBox", redBoxStyle, false );
+展开-XML
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init();">
<mx:Script>
<![CDATA[
// create and store new style declarations.
private function init():void {
StyleManager.registerColorName( "cookbookBlue",0x339966 );
var headerStyleDeclaration:CSSStyleDeclaration =new CSSStyleDeclaration();
headerStyleDeclaration.setStyle( "fontWeight","bold");
headerStyleDeclaration.setStyle( "fontSize", 15 );
headerStyleDeclaration.setStyle( "color",StyleManager.getColorName( "cookbookBlue") );
var msgStyleDeclaration:CSSStyleDeclaration =new CSSStyleDeclaration();
msgStyleDeclaration.setStyle( "fontSize", 12 );
msgStyleDeclaration.setStyle( "color",StyleManager.getColorName( "haloSilver") );
StyleManager.setStyleDeclaration( ".header",headerStyleDeclaration, false);
StyleManager.setStyleDeclaration( ".message",msgStyleDeclaration, true);
}
// clear previously created styles.
private function clickHandler():void {
StyleManager.clearStyleDeclaration( ".header", false);
StyleManager.clearStyleDeclaration( ".message", true);
}
]]>
</mx:Script>
<mx:Label text="I'm a header styled through the StyleManager"
styleName="header"/>
<mx:Text text="I'm a message styled through the StyleManager"
styleName="message" />
<mx:Button label="clear styles" click="clickHandler();" />
</mx:Application>