论坛首页 入门技术论坛

web界面框架的设计之三-- Tree树形菜单的实现

浏览 3369 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (6)
作者 正文
   发表时间:2010-02-28   最后修改:2010-02-28

利用Tree控件实现树形菜单,代码

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="leftinit()">
	<mx:Metadata>
    	[Event(name="leftTreeEvent","MyEvent.TopEvent")]
    </mx:Metadata>
	<mx:Script>
		<![CDATA[
			
			import mx.rpc.remoting.mxml.RemoteObject;
			import mx.rpc.AsyncToken;
			import mx.rpc.AbstractOperation;
			import mx.rpc.AsyncResponder;
			import mx.rpc.events.ResultEvent;
			import mx.controls.Alert;
			import MyEvent.LeftTreeEvent;
			
			private var MenuRo:RemoteObject;
			private var treeDate:XML;
			
			
			private var selectedNode:XML;
			
			private function leftinit():void
		    {
		    	MenuRo = new RemoteObject("menuService"); 
		    	
		    	var menuToken:AsyncToken ;
				var operation:AbstractOperation = MenuRo.getOperation("getTree");
				menuToken = operation.send(2);
				menuToken.addResponder(new AsyncResponder(treeSuccess,null));  
		    }
		    
		    //树回调函数
			private function treeSuccess(result:Object,token:Object=null):void
			{
				var eve:ResultEvent = result as ResultEvent;
				if(eve.result != null)
				{		
					 var returnString:String = eve.result as String;
					 if(returnString !="" && returnString != null){
						 treeDate = new XML(returnString);
						 tree.dataProvider = treeDate;
						 tree.callLater(expandTree);
					 }
				}
			}
			
			//树行自动展开
			private function expandTree():void{   
			     tree.expandChildrenOf(treeDate , true);   
			}
		    
		    public function treeChanged(event:Event):void
		    {
		    	selectedNode=Tree(event.target).selectedItem as XML;
		    	var menuEvent:LeftTreeEvent = new LeftTreeEvent("leftTreeEvent",
		    		selectedNode.@hreflink,selectedNode.@fid);
				dispatchEvent(menuEvent);
		    }
		    
		    
		]]>
	</mx:Script>
	<mx:VBox x="0" y="0" width="100%" height="100%">
		<mx:Tree width="100%" height="100%" id="tree" labelField="@label" 
			showRoot="true" fontSize="14"  change="treeChanged(event)" ></mx:Tree>
	</mx:VBox>
	
</mx:Canvas>

 

  • 大小: 9.8 KB
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics