Usually, anything you want to see in a renderer is set in the data
object itself.

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of sarah_e_boys
Sent: Wednesday, May 30, 2007 5:52 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Extending TreeItemRenderer

 


I would like to know how I pass a string (topicTitleParameter) in to 
the extended TreeItemRenderer class below. 

package samples
{
import mx.controls.treeClasses.*;
import mx.collections.*;

//Item renderer:
public class MyTreeItemRenderer extends TreeItemRenderer {

public var topicTitle:String;

// Define the constructor.
public function MyTreeItemRenderer
(topicTitleParameter:String) {
super();
this.topicTitle = topicTitleParameter;
}

// Override the set method for the data property
// to set the font color and style of each node.
override public function set data(value:Object):void {
super.data = value;
if(TreeListData(super.listData).label == 
this.topicTitle ) {
setStyle("color", 0xff0000);
setStyle("fontWeight", 'bold');
}
else {
setStyle("color", 0x000000);
setStyle("fontWeight", 'normal');
} 
}

// Override the updateDisplayList() method 
// to set the text for each tree node. 
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).item);
var myStr:int = tmp
[0].children().length();
super.label.text = 
TreeListData(super.listData).label + "(" + myStr + ")"; 
}
}
}
}
}

I tried the following:
<mx:Tree id="compBalanced" dataProvider="{xlcBalanced}" 
labelFunction="treeLabel"
labelField="@label" width="400" height="500" 
itemRenderer="samples.MyTreeItemRenderer('GridRow')" />

and get the following error message:
Initializer for 'itemRenderer': cannot parse value of type 
mx.core.IFactory from text 'samples.MyTreeItemRenderer('GridRow')'



 

Reply via email to