I have an item renderer for a list control and I want to delegate the
editing of the object that the item renderer is showing to its
containing control - in fact to the custom control that contains the
list that the item renderer belongs to.
I have set up the item renderer inline something like this (embedded in
my custom control)[snipped for brevity]
<mx:List id="lst_Opportunities" dataProvider="{_opps}">
<mx:itemRenderer>
<mx:Component>
<ns1:my_Renderer/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
snip...
<script>
private function handleEdit(o:Object):void
{
}
</script>
What I then did was add a public function variable, doEdit, to
my_Renderer and a handler for the double-click event which looked for
the doEdit function and called it passing the object associated with the
renderer...
(embedded in my_Renderer, which is just a canvas)
public var onEdit:function = null;
private function onDoubleClick():void
{
if (onEdit != null) onEdit(this.data);
}
This is a pattern that I tend to use a lot in other contexts as it gives
me a great deal of flexibility in re-using code.
The trouble is that I cannot give the item renderer the function pointer
in the declaration, so this code gives a compiler error...
<mx:List id="lst_Opportunities" dataProvider="{_opps}">
<mx:itemRenderer>
<mx:Component>
<ns1:my_Renderer onEdit={handleEdit}/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
The error is "access of undefined property handleEdit".
I'm guessing that the Component tag somehow alters the scope, but I am
wondering how to go about this.
FlexBuilder 2 - although I don't think it should matter.
TIA