If you replace the icon in a subclass, you'll have to remove the old one from 
the display list and add your new one (removeChild/addChild).

Tree has APIs for getting the renderer to choose different icons depending on 
the data.  See Tree styles like defaultLeafIcon, and APIs like iconField  You 
may not need a custom renderer if all you want to change is the icon

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of dfrank76
Sent: Tuesday, November 11, 2008 11:32 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] TreeItemRenderer setting an icon to an embedded image


What is the proper way to set the icon from a TreeItemRenderer when
using an embeded graphic file? I don't want to accidentally create
hundreds of instances of it in memory. TreeItemRenderer.icon is an
instance of IFlexDisplayObject which is implemented by BitmapDataAsset
(the embedded graphic class). When I do the following:

public class MyTreeItemRenderer extends TreeItemRenderer
{

[Embed(source="../../assets/test.jpg")]
public var testIcon:Class;

public function MyTrereItemRenderer() {
super();
}


// 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);
this.icon = new studentIcon();
}
}

I get this RTE:

ArgumentError: Error #2025: The supplied DisplayObject must be a child
of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at
mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$remo
veChild()
at mx.core::UIComponent/removeChild()
at
mx.controls.treeClasses::TreeItemRenderer/commitProperties()
at mx.core::UIComponent/validateProperties()
at mx.managers::LayoutManager/validateClient()
at mx.controls::List/makeRowsAndColumns()
at
mx.controls.listClasses::ListBase/makeRowsAndColumnsWithExtraRows()
at mx.controls.listClasses::ListBase/updateDisplayList()
at mx.controls::List/updateDisplayList()

I can't seem to find a good example of a TreeItemRenderer on the web
that uses the icon field to control the icon.

Dave

Reply via email to