復制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
fontFamily="simsun" fontSize="12"
layout="absolute" creationComplete="menu.send();" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var strUrl:String = "TreeMenus.xml";
[Bindable]
private var menus:XML;
[Bindable]
[Embed("open.gif")]
public var openicon:Class;
[Bindable]
[Embed("close.gif")]
public var closeicon:Class;
[Bindable]
[Embed("leaf.gif")]
public var leaficon:Class;
private function init():void
{
this.strUrl = this.parameters.url;
}
private function LoadMenu(event:ResultEvent):void
{
menus = XML(event.result);
var results:XMLList = menus.node;
tree1.dataProvider = results;
}
//菜單圖標設置
private function treeIcon(item:Object):Class
{
var node:XML = XML(item);
trace('icon:' + node.@icon);
var str : String = node.@icon;
//已經設置圖標
if(node.hasOwnProperty("@icon"))
{
if(node.@icon == 'openicon')
{
return openicon;
}
if(node.@icon == 'closeicon')
{
return closeicon;
}
if(node.@icon == 'leaficon')
{
return leaficon;
}
}
else
{
//如果沒定義icon就直接用默認的
if(!tree1.dataDescriptor.isBranch(item))
{
return tree1.getStyle("defaultLeafIcon");
}
if(tree1.isItemOpen(item))
{
return tree1.getStyle("folderOpenIcon");
}
else
{
return tree1.getStyle("folderClosedIcon");
}
}
return null;
}
/**
* 菜單樹單項點擊事件
* */
private function itemClickHandler(evt:ListEvent):void
{
var item:Object = Tree(evt.currentTarget).selectedItem;
if (tree1.dataDescriptor.isBranch(item))
{
//tree1.expandItem(item, !groupTree.isItemOpen(item), true);
}
else
{
//得到節點對象
var node:XML = XML(item);
//如果有屬性href
if(node.hasOwnProperty("@href") && node.hasOwnProperty("@target"))
{
openURL(node.@href,node.@target);
}
if(node.hasOwnProperty("@href") && (node.hasOwnProperty("@target") == false))
{
//沒有指定target默認在新窗口中打開
openURL(node.@href,"_blank");
}
}
}
//頁面跳轉的方法
private function openURL(url:String ,target:String):void
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request,target);
}
]]>
</mx:Script>
<mx:HTTPService url="{strUrl}" useProxy="false"
showBusyCursor="true" result="LoadMenu(event)" resultFormat="xml"/>
<mx:Tree iconFunction="treeIcon" labelField="@label" itemClick="itemClickHandler(event)"/>
</mx:Application>
復制代碼 代碼如下:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="tree"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param value="${ctx}/js/as/menu.swf" />
<param value="high" />
<param value="#869ca7" />
<param value="sameDomain" />
<!-- 指定菜單的數據源 -->
<param value="url=${ctx}/user/user!renderMenu.do?id=${user.usid}" />
<embed src="http://www.jb51.net/article/tree.swf" quality="high" bgcolor="#869ca7"
width="242"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
其中url可以指定xml文件的位置或者render的鏈接
示例文件xml:
<?xml version='1.0' encoding='utf-8'?>
<menus>
<node label='系統管理' icon="openicon">
<node label='用戶管理' icon="closeicon"
target='mainFrame' />
<node label='權限管理'
target='mainFrame' />
<node label='角色管理'
target='mainFrame' />
<node label='域管理'
target='mainFrame' />
<node label='測試'>
<node label='sub folder' href='' target='mainFrame' />
</node>
</node>
<node label='客服'>
<node label='終端信息查詢' href='' target='mainFrame' />
<node label='客服問題-解答記錄' href='' target='mainFrame' />
</node>
</menus>
(編輯:武林網)
新聞熱點
疑難解答