professional-flex-code-26-RuntimeCSSModule.mx [swf] flex
<?xml version="1.0" encoding="utf-8"?> <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.styles.StyleManager; import mx.events.StyleEvent; private var lastCSS:String; private function changeCSS( name:String ):void { // If you do not unload the last style // previous style settings will be in affect unloadCSS( false ); var styleEvent:IEventDispatcher = StyleManager.loadStyleDeclarations( name, true ); lastCSS = name; //styleEvent.addEventListener( StyleEvent.ERROR, showError ); //styleEvent.addEventListener( StyleEvent.COMPLETE, completed ); } private function unloadCSS( updateFlag:Boolean ):void { if( lastCSS ) StyleManager.unloadStyleDeclarations( lastCSS, updateFlag ); } public function completed( event:StyleEvent ):void { Alert.show( event.type ); } ]]> </mx:Script> <mx:Panel id="pnlApp" title="Sample Application" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" layout="vertical" horizontalAlign="center"> <mx:Label text="Please fill out the form below and click on Login!" /> <mx:Form> <mx:FormItem label="Username:"> <mx:TextInput id="txtUsername" /> </mx:FormItem> <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 horizontalAlign="center" width="100%"> <mx:Button id="btnUnload" cornerRadius="0" click="unloadCSS( true )" label="one" fillColors="[#7C929D,#CCCCCC]" /> <mx:Button id="btnBlue" cornerRadius="0" click="changeCSS( 'blueCSS.swf' )" label="two" fillColors="[#336699,#5588BB]" /> <mx:Button id="btnRed" cornerRadius="0" click="changeCSS( 'redCSS.swf' )" label="three" fillColors="[#993333,#BB5555]" /> </mx:HBox> </mx:Module>
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.