在FLEX中动态更换CSS样式表

StyleManager类的StyleManager.loadStyleDeclarations() 方法.
示例:


代码:

<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2007/12/12/loading-cascading-style-sheets-on-the-fly-using-the-flex-stylemanager-class/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle" >

    
< mx:Script >
        
<![CDATA[
            import mx.styles.StyleManager;

            private function loadStyles(styleURL:String):void {
                StyleManager.loadStyleDeclarations(styleURL);
            }
        
]]>
    
</ mx:Script >

    
< mx:ApplicationControlBar  dock ="true" >
        
< mx:ComboBox  id ="comboBox"
                prompt
="Please select a style"
                change
="loadStyles(comboBox.selectedItem.data);" >
            
< mx:dataProvider >
                
< mx:Array >
                    
< mx:Object  label ="red"  data ="styles/red.swf"   />
                    
< mx:Object  label ="green"  data ="styles/green.swf"   />
                    
< mx:Object  label ="blue"  data ="styles/blue.swf"   />
                
</ mx:Array >
            
</ mx:dataProvider >
        
</ mx:ComboBox >
    
</ mx:ApplicationControlBar >

</ mx:Application >

你可能感兴趣的:(Flex)