|
|
可能很多人在写Flex程序的时候为了界面的美化,都会用到css,这里有一个动态换肤的实现。
原理就是将各种不同的css文件先编译成swf,然后用StyleManager类的loadStyleDeclarations方法加载换肤的swf。代码如下:
<?xml version="1.0" encoding="utf-8"?><mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="16" ><mx:LinkButton width="16" height="16" color="#ff0000" icon="@Embed('assets/png/springbt.png')" click="onChangeStyle(event)" x="0" id="spring" toolTip="春季主题"/><mx:LinkButton width="16" height="16" color="#ff0000" icon="@Embed('assets/png/summerbt.png')" click="onChangeStyle(event)" x="17" id="summer" toolTip="夏季主题"/><mx:LinkButton width="16" height="16" color="#00ff00" icon="@Embed('assets/png/autumnbt.png')" click="onChangeStyle(event)" x="34" id="autumn" toolTip="秋季主题"/><mx:LinkButton width="16" height="16" color="#ff0000" icon="@Embed('assets/png/winterbt.png')" click="onChangeStyle(event)" x="51" id="winter" toolTip="冬季主题"/><mx:LinkButton width="16" height="16" color="#ff0000" icon="@Embed('assets/png/default.PNG')" click="onChangeStyle(event)" x="68" id="defult" toolTip="默认主题"/><mx:Script><![CDATA[import com.yyhy.webgis.model.ModelLocator;private var __model:ModelLocator = ModelLocator.getInstance();private function onChangeStyle(event:MouseEvent):void{if(event.currentTarget == spring){__model.selectskin = "Spring";StyleManager.loadStyleDeclarations("assets/skins/color/Spring.swf");}else if(event.currentTarget == summer){__model.selectskin = "Summer";StyleManager.loadStyleDeclarations("assets/skins/color/summer.swf");}else if(event.currentTarget == autumn){__model.selectskin = "Autumn";StyleManager.loadStyleDeclarations("assets/skins/color/autumn.swf");}else if(event.currentTarget == winter){__model.selectskin = "Winter";StyleManager.loadStyleDeclarations("assets/skins/color/winter.swf");}else if(event.currentTarget == defult){__model.selectskin = "Start";StyleManager.loadStyleDeclarations("assets/skins/color/start.swf");}else{__model.selectskin = null;return;}}]]></mx:Script></mx:Canvas> |
|