---
title: "flex css动态加载"
author: "demojava"
date: "2012-01-07T10:14:21Z"
tags: []
categories: ["Web前端"]
slug: "flex-css"
draft: false
lastmod: "2012-01-07T10:14:21Z"
id: 1337123
url: "https://demojava.iteye.com/blog/1337123"
---

flex css知识回顾：
<http://demojava.iteye.com/blog/1199379 >
核心代码：

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

```

源码清单：

```xml

<?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>

```

附件为源码文件