Load and unload style with StyleManager : StyleManager « Style « Flex






Load and unload style with StyleManager

Load and unload style with StyleManager
         
<?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

1.To remove a CSSStyleDeclaration object, use StyleManager.clearStyleDeclaration()To remove a CSSStyleDeclaration object, use StyleManager.clearStyleDeclaration()
2.Use StyleManager.loadStyleDeclarations() to load CSS-based SWF file at run timeUse StyleManager.loadStyleDeclarations() to load CSS-based SWF file at run time
3.Adding global CSS styles with StyleManagerAdding global CSS styles with StyleManager
4.Set the fontSize style to 15 and the color to 0x9933FF on all Button controls in the Spark namespaceSet the fontSize style to 15 and the color to 0x9933FF on all Button controls in the Spark namespace
5.Loadng a style sheet when you click the buttonLoadng a style sheet when you click the button
6.Use StyleManager to apply styles to all classes or specified classesUse StyleManager to apply styles to all classes or specified classes
7.ColorFormat StyleManagerColorFormat StyleManager
8.Store selectorss names that are registered with the StyleManager in an Array.Store selectorss names that are registered with the StyleManager in an Array.
9.Color Format with StyleManagerColor Format with StyleManager
10.Using Embedded gif image with StyleManagerUsing Embedded gif image with StyleManager
11.Use hexadecimal format or the VGA color nameUse hexadecimal format or the VGA color name
12.Compare Color value after convert color value to string value with Color.toString()Compare Color value after convert color value to string value with Color.toString()