flex css动态加载

flex css知识回顾:
[url]http://demojava.iteye.com/blog/1199379 [/url]
核心代码:

StyleManager.unloadStyleDeclarations(styleURL);
StyleManager.loadStyleDeclarations('style3.swf');

源码清单:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
backgroundImage="{bgSWF}"
width="800"
height="200"
creationComplete="initApp()"
>
<mx:Script>
<![CDATA[
import mx.managers.CursorManager; //引用CursorManager类
import mx.events.MenuEvent;//引用MenuEvent类
import mx.styles.StyleManager;//引用StyleManager类

[Embed(source="hand.png")] //绑定光标图形到handCursorSymbol
private var handCursorSymbol:Class;

[Embed(source="bg.swf")] //背景图形绑定到bgSWF
private var bgSWF:Class;

private var styleURL:String="";//用以存储当前样式的路径
private var cursorID:Number = 0; //定义光标的ID
public function initApp():void
{
styleURL="style1.swf";//当前样式路径为"style1.swf"
StyleManager.loadStyleDeclarations("style1.swf");//加载style1样式
}
//鼠标移动到菜单上时的事件处理
public function menuRollOverHandle(e:MenuEvent):void
{
if(String(e.item.@link)!="")//若属性link中有值,显示手形
{
//创建光标
cursorID = CursorManager.setCursor(handCursorSymbol);
}
}
//鼠标移出菜单时的事件处理
public function menuRollOutHandle(e:MenuEvent):void
{
CursorManager.removeCursor(cursorID); //删除光标
}
]]>
</mx:Script>
<mx:VBox verticalGap="60">
<mx:MenuBar id="myMenu" labelField="@label" alpha="0.6"
itemRollOver="menuRollOverHandle(event)"
itemRollOut="menuRollOutHandle(event)"
>
<mx:XMLList xmlns="" id="menuData">
<menuitem label="Mail">
<menuitem label="Inbox"/>
<menuitem label="Personal Folder">
<menuitem label="Demo" link="index1.html"/>
<menuitem label="Personal"/>
<menuitem label="Saved Mail"/>
<menuitem label="bar" link="web/index.html"/>
</menuitem>
</menuitem>
<menuitem label="Calendar"/>
<menuitem label="Sent"/>
<menuitem label="Trash"/>
</mx:XMLList>
</mx:MenuBar>
<mx:HBox horizontalGap="5">
<!--"样式1"按钮,单击时先清除原样式,再加载新样式-->
<mx:Button id="btnStyle1" label="样式1" click="StyleManager.unloadStyleDeclarations(styleURL);StyleManager.loadStyleDeclarations('style1.swf');styleURL='style1.swf';"/>
<!--"样式2"按钮,单击时先清除原样式,再加载新样式-->
<mx:Button id="btnStyle2" label="样式2" click="StyleManager.unloadStyleDeclarations(styleURL);StyleManager.loadStyleDeclarations('style2.swf');styleURL='style2.swf';"/>
<!--"样式3"按钮,单击时先清除原样式,再加载新样式-->
<mx:Button id="btnStyle3" label="样式3" click="StyleManager.unloadStyleDeclarations(styleURL);StyleManager.loadStyleDeclarations('style3.swf');styleURL='style3.swf';"/>

</mx:HBox>
</mx:VBox>
</mx:Application>

附件为源码文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值