`
zhanshenlvbu
  • 浏览: 109322 次
社区版块
存档分类
最新评论

Flex自定义Tree图标

    博客分类:
  • Flex
阅读更多

1.数据源为xml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
  <![CDATA[
   import mx.collections.XMLListCollection;
 
   [Embed(source="assets/max_over.gif")]          //这是图片的相对地址
         [Bindable]
         public var OKicon:Class;
        
         [Embed(source="assets/close_over.gif")]          //这是图片的相对地址
         [Bindable]
         public var NOicon:Class;
  
   //设置不同图表          
   private function iconFun(item:Object):*
   {
    var xml:XML     = item as XML;
   
    if(xml.attribute("bool") == true)
     return OKicon;
    else if(xml.attribute("bool") == false)
     return NOicon;
   } 
  ]]>
</mx:Script>

<mx:XMLListCollection id="datatree" >
  <mx:source>
            <mx:XMLList>
                <node label="NO1" bool="false">
                    <node label="NO11" bool="false">
                        <node label="NO111" bool="false"/>
                    </node>
                    <node label="NO22" bool="true"/>
                </node>
                <node label="NO2" bool="true">
                    <node label="NO11" bool="false">
                     <node label="NO111" bool="false"/>
                    </node>
                    <node label="NO22" bool="true">
                     <node label="NO222" bool="false"/>
                    </node>
                </node>
            </mx:XMLList>
  </mx:source>
</mx:XMLListCollection>

<mx:Tree id="tree" y="40" width="100%" height="100%" fontFamily="Arial" fontSize="12"
   dataProvider="{datatree}" labelField="@label" iconFunction="iconFun" />
</mx:Application> 

 

 

 

 

2.数据源为Object

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
  <![CDATA[
   import mx.collections.XMLListCollection;
 
        [Bindable]
        public var firstObj:TreeNode = new TreeNode();
        [Bindable]
        public var firstObj1:TreeNode = new TreeNode();
        [Bindable]
        public var firstObj2:TreeNode = new TreeNode();

        [Bindable]
        [Embed(source="assets/treeicon/SUBNETWORK.png")] 
        public var SUBNETWORK:Class; 

        [Bindable]
        [Embed(source="assets/treeicon/NAD.png")] 
        public var NAD:Class; 

        [Bindable]
        [Embed(source="assets/treeicon/CrossingServer.png")] 
        public var CrossingServer:Class; 

        [Bindable]
        [Embed(source="assets/treeicon/Camera.png")] 
        public var Camera:Class;   

        //设置不同图标          
     private function iconFun(item:Object):*
        {
                var tn:TreeNode     = item as TreeNode;
				
                if(tn.type == "NAD")
	        return NAD;
                else if(tn.type == "CrossingServer")
	        return CrossingServer;
                else if(tn.type == "Camera")
	        return Camera;
                else if(tn.type == "SUBNETWORK")
	        return SUBNETWORK;   
        } 
  ]]>
</mx:Script>

        <mx:Tree id="sourcesTree" x="0" top="0" width="100%" height="100%" dataProvider="{firstObj}" iconField="head" labelField="labels" showRoot="true" iconFunction="iconFun" >
</mx:Application> 

  

    TreeNode.as代码

package com.lsun.irms.nms.topo.vo
{

	public class TreeNode
	{
		private var _labels:String;
		private var _type:String;
		private var _head:Class;
		private var _children:Array;

		public function get children():Array
		{
			return _children;
		}

		public function set children(value:Array):void
		{
			_children = value;
		}

		public function get head():Class
		{
			return _head;
		}

		public function set head(value:Class):void
		{
			_head = value;
		}

		public function get type():String
		{
			return _type;
		}

		public function set type(value:String):void
		{
			_type = value;
		}

		public function get labels():String
		{
			return _labels;
		}

		public function set labels(value:String):void
		{
			_labels = value;
		}

	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics