完成作用:
1.由外界主要参数flashvars特定数据源的文档部位或render连接.
2.在源数据信息上添href和target属性来操纵开启对话框.
3.可自定父节点和子连接点标志,不设定选用系统软件默认设置.
立即上源代码:
复制代码 编码以下:
<?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();" width="242" height="442" 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}" id="menu" useProxy="false"
showBusyCursor="true" result="LoadMenu(event)" resultFormat="xml"/>
<mx:Tree iconFunction="treeIcon" id="tree1" width="100%" height="100%" labelField="@label" itemClick="itemClickHandler(event)"/>
</mx:Application>

启用的情况下在flashvars里边再加上url=xxx
复制代码 编码以下:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="tree" width="242" height="442"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="${ctx}/js/as/menu.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<!-- 特定莱单的数据源 -->
<param name="flashvars" value="url=${ctx}/user/user!renderMenu.do?id=${user.usid}" />
<embed src="tree.swf" quality="high" bgcolor="#869ca7"
width="242" height="442" name="tree" align="middle"
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"
href='/main/user/user-list.jsp' target='mainFrame' />
<node label='管理权限' href='/main/user/action-list.jsp'
target='mainFrame' />
<node label='人物角色管理方法' href='/main/user/role-list.jsp'
target='mainFrame' />
<node label='域管理方法' href='/main/user/user-list.jsp'
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>

Flex 基于数据源的Menu Tree实现代码 Tree Menu 数据源 Flex  第1张