Flex 改变树结点图标的2种方法介绍(flex改变布局方向)深度揭秘

随心笔谈2年前发布 编辑
166 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

xmlns:s=”library://ns.adobe.com/flex/spark”

xmlns:mx=”library://ns.adobe.com/flex/mx” minWidth=”955″ minHeight=”600″>

]]>

id=”myTree”

showRoot=”false”

labelField=”@label”

itemRenderer=”com.flex.tree.dynamicicontree.IconTreeRenderer”>

package com.flex.tree.dynamicicontree

{

import flash.xml.*;

import mx.collections.*;

import mx.controls.Image;

import mx.controls.listClasses.*;

import mx.controls.treeClasses.*;

import mx.styles.StyleManager;

public class IconTreeRenderer extends TreeItemRenderer

{

protected var myImage:ImageRenderer;

private var imageWidth:Number=16;

private var imageHeight:Number=16;

private static var defaultImg:String=”windows.png”;

public function IconTreeRenderer ()

{

super();

}

override protected function createChildren():void

{

super.createChildren();

myImage=new ImageRenderer();

myImage.source=defaultImg;

myImage.width=imageWidth;

myImage.height=imageHeight;

myImage.setStyle( “verticalAlign”, “middle” );

addChild(myImage);

}

//通过覆盖data方法来动态设置tree的节点图标

override public function set data(value:Object):void

{

super.data=value;

var imageSource:String=value.@iconName.toString();

if(imageSource!=””)

{

myImage.source=imageSource;

}else{

myImage.source=defaultImg;

}

}

//隐藏原有图标,并设置它的坐标

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void

{

super.updateDisplayList(unscaledWidth, unscaledHeight);

if(super.data !=null)

{

if (super.icon !=null)

{

myImage.x=super.icon.x;

myImage.y=2;

super.icon.visible=false;

}

else

{

myImage.x=super.label.x;

myImage.y=2;

super.label.x=myImage.x + myImage.width + 17;

}

}

}

}

}

package com.flex.tree.dynamicicontree

{

import mx.controls.Image;

public class ImageRenderer extends Image

{

private var defaultURL:String=”assets/icon/”;

public var iconName:String;

public function ImageRenderer()

{

super();

}

override public function set source(url:Object):void{

super.source=defaultURL + url;

iconName=url as String;

}

}

}

© 版权声明

相关文章