PDA

View Full Version : custom itemrenderer icons


megaera
11-06-2008, 06:57 PM
Hi, i have what i hope is a simple question, but i've had no luck finding any info in the flex docs.

For a List component i'm using, i'm specifying an itemRenderer called MyItemRenderer, and have an iconFunction defined also.

MyItemRenderer is a VBox with some extra formatting.

My question is: in MyItemRenderer, what do i have to do to utilize the results of the iconFunction used by the List? i.e., how to i place an icon in the extended VBox that will populate based on the icon source returned by the iconFunction at the List? hope that makes sense.

thanks for your help!

tsj4
11-06-2008, 08:46 PM
I am not sure if that is native behavior of the List Component but if it is did you include super() to inherit the functionality of the default itemRenderer?

megaera
11-06-2008, 09:00 PM
Thanks for your reply.
It is native behavior of the List. my current implementation uses the default behavior of the List with an iconFunction assigned which places a small icon next to each item in the list.

Super can only be invoked in a class constructor. being that this is a custom component based on a VBox, there isn't a constructor.

What i need to do now is specify an itemRenderer for my List so that I can add some additional formatting to the list items. For this I'm using a custom component based on VBox. This is the code currently in MyItemRenderer.mxml. there isn't much in here but a label yet, the first thing im trying to do is retain the default behavior of the List items by having the icon and label:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[

private var resultData:Object;

[Bindable]
override public function get data():Object
{
return this.resultData;
}

override public function set data(value:Object):void
{
if (value) this.resultData = value;
}

private function titleClickHandler(event:MouseEvent):void
{
var titleEvent:Event = new Event("TitleClickEvent",true,false);

dispatchEvent(titleEvent);
}
]]>
</mx:Script>
<mx:HBox>
<mx:Label id="resultTitle" enabled="true" text="{data.listing}" click="titleClickHandler(event)"/>
</mx:HBox>
</mx:VBox>

tsj4
11-06-2008, 09:59 PM
something like so

private var myRenderer:ClassFactory=new ClassFactory(myClass);

myList.dataProvider = myRenderer


or ..

myList.itemRenderer = new ClassFactory(myClass);


Not sure though.