实现功能
由外部参数flashvars指定数据源的文件位置或render链接
在源数据上加href和target属性来控制打开窗口
可自定义父节点和子节点图标不设置采用系统默认
直接上源码
<?xmlversion=encoding=utf?>
<mx:Applicationxmlns:mx=
fontFamily=simsunfontSize=
layout=absolutecreationComplete=menusend();width=height=initialize=init()>
<mx:Script>
<![CDATA[
importntrolsAlert;
importmxeventsListEvent;
importllectionsArrayCollection;
importmxrpceventsResultEvent;
[Bindable]
privatevarstrUrl:String=TreeMenusxml;
[Bindable]
privatevarmenus:XML;
[Bindable]
[Embed(opengif)]
publicvaropenicon:Class;
[Bindable]
[Embed(closegif)]
publicvarcloseicon:Class;
[Bindable]
[Embed(leafgif)]
publicvarleaficon:Class;
privatefunctioninit():void
{
thisstrUrl=thisparametersurl;
}
privatefunctionLoadMenu(event:ResultEvent):void
{
menus=XML(eventresult);
varresults:XMLList=menusnode;
treedataProvider=results;
}
//菜单图标设置
privatefunctiontreeIcon(item:Object):Class
{
varnode:XML=XML(item);
trace(icon:+node@icon);
varstr:String=node@icon;
//已经设置图标
if(nodehasOwnProperty(@icon))
{
if(node@icon==openicon)
{
returnopenicon;
}
if(node@icon==closeicon)
{
returncloseicon;
}
if(node@icon==leaficon)
{
returnleaficon;
}
}
else
{
//如果没定义icon就直接用默认的
if(!treedataDescriptorisBranch(item))
{
returntreegetStyle(defaultLeafIcon);
}
if(treeisItemOpen(item))
{
returntreegetStyle(folderOpenIcon);
}
else
{
returntreegetStyle(folderClosedIcon);
}
}
returnnull;
}
/***//**
*菜单树单项点击事件
**/
privatefunctionitemClickHandler(evt:ListEvent):void
{
varitem:Object=Tree(evtcurrentTarget)selectedItem;
if(treedataDescriptorisBranch(item))
{
//treeexpandItem(item!groupTreeisItemOpen(item)true);
}
else
{
//得到节点对象
varnode:XML=XML(item);
//如果有属性href
if(nodehasOwnProperty(@href)&&nodehasOwnProperty(@target))
{
openURL(node@hrefnode@target);
}
if(nodehasOwnProperty(@href)&&(nodehasOwnProperty(@target)==false))
{
//没有指定target默认在新窗口中打开
openURL(node@href_blank);
}
}
}
//页面跳转的方法
privatefunctionopenURL(url:Stringtarget:String):void
{
varrequest:URLRequest=newURLRequest(url);
navigateToURL(requesttarget);
}
]]>
</mx:Script>
<mx:HTTPServiceurl={strUrl}id=menuuseProxy=false
showBusyCursor=trueresult=LoadMenu(event)resultFormat=xml/>
<mx:TreeiconFunction=treeIconid=treewidth=%height=%labelField=@labelitemClick=itemClickHandler(event)/>
</mx:Application>
调用的时候在flashvars里面加上url=xxx
<objectclassid=clsid:DCDBEAEDcfB
id=treewidth=height=
codebase=>
<paramname=movievalue=${ctx}/js/as/menuswf/>
<paramname=qualityvalue=high/>
<paramname=bgcolorvalue=#ca/>
<paramname=allowScriptAccessvalue=sameDomain/>
<!指定菜单的数据源>
<paramname=flashvarsvalue=url=${ctx}/user/user!renderMenudo?id=${userusid}/>
<embedsrc=treeswfquality=highbgcolor=#ca
width=height=name=treealign=middle
play=true
loop=false
quality=high
allowScriptAccess=sameDomain
type=application/xshockwaveflash
pluginspage=>
</embed>
</object>
其中url可以指定xml文件的位置或者render的链接
示例文件xml
<?xmlversion=encoding=utf?>
<menus>
<nodelabel=系统管理icon=openicon>
<nodelabel=用户管理icon=closeicon
target=mainFrame/>
<nodelabel=权限管理
target=mainFrame/>
<nodelabel=角色管理
target=mainFrame/>
<nodelabel=域管理
target=mainFrame/>
<nodelabel=测试>
<nodelabel=subfoldertarget=mainFrame/>
</node>
</node>
<nodelabel=客服>
<nodelabel=终端信息查询target=mainFrame/>
<nodelabel=客服问题解答记录target=mainFrame/>
</node>
</menus>
源码下载点击