Flex 基于数据源的Menu Tree实现代码(flappybird源代码)快来看

随心笔谈11个月前发布 admin
97 0

fontFamily=”simsun” fontSize=”12″

layout=”absolute” creationComplete=”menu.send();” width=”242″ height=”442″ initialize=”init()”>

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);

}

]]>

showBusyCursor=”true” result=”LoadMenu(event)” resultFormat=”xml”/>

© 版权声明

相关文章