[flexcoders] Generic itemRenderer for Canvas based controls

2008-12-04 Thread simonjpalmer
I have a TileList control that I want to populate at runtime with a
collection of custom controls determined by preferences held on the
user which I retrieve after they log in.  All of the custom controls
are based on Canvas.  

My current approach is to have an Array into which I push the
appropriate controls after login success and bind that array as the
dataProvider on my TileList control.  The trouble is that the controls
don't get rendered because there is no itemRenderer defined for the
TileList.

So I attempted to create a generic itemRenderer based on Canvas which
overrides the set data() method and adds the inbound control as a child...

override public function set data(value:Object):void
{
if (value == null) return;
var cvs:Canvas = value as Canvas;
this.addChild(cvs);
}

However, this throws index out of bounds errors doing a getChild(0)
deep in the bowels of the framework code associated with the dynamic
itemRenderer component, which I don't seem to be able to overcome in
spite of altering the sequence in which things get created, and
fiddling around with the creationPolicy of the custom controls.

So I'm a bit stuck and wondering whether there is a different approach
or I'm just doing something wrong.

Any ideas?



RE: [flexcoders] Generic itemRenderer for Canvas based controls

2008-12-04 Thread Alex Harui
Flex 3 should have the createItemRenderer() method.  Override that and return 
an IListItemRenderer of your choice

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
simonjpalmer
Sent: Thursday, December 04, 2008 1:54 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Generic itemRenderer for Canvas based controls


I have a TileList control that I want to populate at runtime with a
collection of custom controls determined by preferences held on the
user which I retrieve after they log in. All of the custom controls
are based on Canvas.

My current approach is to have an Array into which I push the
appropriate controls after login success and bind that array as the
dataProvider on my TileList control. The trouble is that the controls
don't get rendered because there is no itemRenderer defined for the
TileList.

So I attempted to create a generic itemRenderer based on Canvas which
overrides the set data() method and adds the inbound control as a child...

override public function set data(value:Object):void
{
if (value == null) return;
var cvs:Canvas = value as Canvas;
this.addChild(cvs);
}

However, this throws index out of bounds errors doing a getChild(0)
deep in the bowels of the framework code associated with the dynamic
itemRenderer component, which I don't seem to be able to overcome in
spite of altering the sequence in which things get created, and
fiddling around with the creationPolicy of the custom controls.

So I'm a bit stuck and wondering whether there is a different approach
or I'm just doing something wrong.

Any ideas?