PDA

View Full Version : help with custom item renderer


sbeausol
02-14-2009, 04:00 AM
I've been able to implement a custom Text Color Item Renderer for a datagrid based off of this post http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html. I've added 2 classes, a ComputedStylesColumn and ComputedStylesRenderer and I can successfully implement this in the mxml file, but I was hoping to build my datagrids dynamically with actionscript.

the mxml that works:

<mx:DataGrid id="dg1" initialize="dg1.dataProvider = dp" paddingTop="0" paddingBottom="0" verticalAlign="middle" >
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name" width="140"/>
<mx:DataGridColumn headerText="Symbol" dataField="symbol" width="60" />
<local:ComputedStylesColumn headerText="Price" dataField="price"
stylesFunction="computeStyles" itemRenderer="ComputedStylesRenderer" />
</mx:columns>
</mx:DataGrid>

I've been able to reconstruct most things in actionscript except for the itemRenderer="ComputedStylesRenderer".

when I try this:

var custColumn1:ComputedStylesColumn = new ComputedStylesColumn();
custColumn1.dataField = "price";
custColumn1.headerText = "Price";
custColumn1.width = 75;
custColumn1.stylesFunction = computeStyles;

Everything works except:

custColumn1.itemRenderer = ComputedStylesRenderer();
"Implicit coercion of a value of type ComputedStylesRenderer to an unrelated type mx.core:IFactory"

Sly_cardinal
02-14-2009, 09:40 AM
When setting this up through actionscript you need to pass through an instance of the ClassFactory class (which implements the IFactory interface).

Check out this page in the docs:
http://livedocs.adobe.com/flex/2/langref/mx/core/ClassFactory.html

Here is the relevant code snippet:

var productRenderer:ClassFactory = new ClassFactory(ComputedStylesRenderer);
custColumn1.itemRenderer = productRenderer;

sbeausol
02-14-2009, 01:36 PM
yeah I figured there was something I had to create, but wasn't sure. This works perfect!

Thanks!