Monday, May 10, 2010

Change Color, weight , font size of tree node

Write a Actionscript class which extends “TreeItemRenderer” as below, and use this class in ur tree tag as





Actionscript class
package
{
import mx.controls.treeClasses.*;
import mx.collections.*;
public class MyTreeItemRenderer extends TreeItemRenderer
{

public function MyTreeItemRenderer()
{
super();
mouseEnabled = false;
}
override public function set data(value:Object):void
{
super.data = value;
if(TreeListData (super.listData).hasChildren)
{
setStyle(“color”, 0xff0000);
setStyle(“fontWeight”, ‘bold’);
}
else
{
setStyle(“color”, 0×000000);
setStyle(“fontWeight”, ‘normal’);

}
}

override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(super.data)
{
if(TreeListData(super.listData).hasChildren)
{
var tmp:XMLList = new XMLList(TreeListData(super.listData).node);
var myStr:int =tmp[0].children().length();
super.label.text = TreeListData(super.listData).text + “(” + myStr + “)”;
}

}

}
}
}

Regards,
Ranjit Sail

1 comment:

  1. To good, Just what I was looking for...

    ReplyDelete