欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

flex css动态加载

程序员文章站 2022-04-29 19:49:17
...
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([email protected])!="")//若属性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>

附件为源码文件