實現功能
直接上源碼
<?xml version=
<mx:Application xmlns:mx=
fontFamily=
layout=
<mx:Script>
<![CDATA[
import ntrols
import mx
import llections
import mx
[Bindable]
private var strUrl:String =
[Bindable]
private var menus:XML;
[Bindable]
[Embed(
public var openicon:Class;
[Bindable]
[Embed(
public var closeicon:Class;
[Bindable]
[Embed(
public var leaficon:Class;
private function init():void
{
this
}
private function LoadMenu(event:ResultEvent):void
{
menus = XML(event
var results:XMLList = menus
tree
}
//菜單圖標設置
private function treeIcon(item:Object):Class
{
var node:XML = XML(item);
trace(
var str : String = node
//已經設置圖標
if(node
{
if(node
{
return openicon;
}
if(node
{
return closeicon;
}
if(node
{
return leaficon;
}
}
else
{
//如果沒定義icon就直接用默認的
if(!tree
{
return tree
}
if(tree
{
return tree
}
else
{
return tree
}
}
return null;
}
/** *//**
* 菜單樹單項點擊事件
* */
private function itemClickHandler(evt:ListEvent):void
{
var item:Object = Tree(evt
if (tree
{
//tree
}
else
{
//得到節點對象
var node:XML = XML(item);
//如果有屬性href
if(node
{
openURL(node
}
if(node
{
//沒有指定target默認在新窗口中打開
openURL(node
}
}
}
//頁面跳轉的方法
private function openURL(url:String
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request
}
]]>
</mx:Script>
<mx:HTTPService url=
showBusyCursor=
<mx:Tree iconFunction=
</mx:Application>
調用的時候在flashvars裡面加上url=xxx
<object classid=
id=
codebase=
<param name=
<param name=
<param name=
<param name=
<!
<param name=
<embed src=
width=
play=
loop=
quality=
allowScriptAccess=
type=
pluginspage=
</embed>
</object>
其中url可以指定xml文件的位置或者render的鏈接
示例文件xml
<?xml version=
<menus>
<node label=
<node label=
target=
<node label=
target=
<node label=
target=
<node label=
target=
<node label=
<node label=
</node>
</node>
<node label=
<node label=
<node label=
</node>
</menus>
源碼下載
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19340.html