Check out outerDocument: The <mx:Component> tag defines a new scope within an MXML file, where the local scope of the item renderer or item editor is defined by the MXML code block delimited by the <mx:Component> and </mx:Component> tags. To access elements outside of the local scope of the item renderer or item editor, you prefix the element name with the outerDocument keyword.
Paul ----- Original Message ----- From: "simonjpalmer" <[email protected]> To: <[email protected]> Sent: Wednesday, January 14, 2009 10:59 AM Subject: [flexcoders] Passing a function reference to an item renderer >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 > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > >

