Change CSS style at runtime
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
import mx.controls.Alert;
import mx.styles.StyleManager;
import mx.events.StyleEvent;
private var lastCSS:String;
private function changeCSS( name:String ):void{
unloadCSS( false );
var styleEvent:IEventDispatcher = StyleManager.loadStyleDeclarations( name, true );
lastCSS = name;
}
private function unloadCSS( updateFlag:Boolean ):void{
if( lastCSS )
StyleManager.unloadStyleDeclarations( lastCSS, updateFlag );
}
</mx:Script>
<mx:Panel id="pnlApp" title="Sample Application" layout="vertical" horizontalAlign="center">
<mx:Label text="Title" />
<mx:Form>
<mx:FormItem label="Password:">
<mx:TextInput id="txtPassword" displayAsPassword="true" />
</mx:FormItem>
</mx:Form>
<mx:Button id="btnTrace" label="Login" styleName="sLogin" />
</mx:Panel>
<mx:HBox>
<mx:Button id="btnUnload" cornerRadius="0" click="unloadCSS( true )" label="Unload"/>
<mx:Button id="btnBlue" cornerRadius="0" click="changeCSS( 'a.swf' )" label="Load CSS in SWF"/>
</mx:HBox>
</mx:Application>
Related examples in the same category