六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 143|回复: 0

Flex 动态换肤

[复制链接]

升级  34.67%

26

主题

26

主题

26

主题

秀才

Rank: 2

积分
102
 楼主| 发表于 2013-2-7 23:21:00 | 显示全部楼层 |阅读模式
    可能很多人在写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> 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表