How to call a function from itemRenderer

34 views
Skip to first unread message

McRain

unread,
Sep 11, 2009, 12:21:27 PM9/11/09
to Flex India Community
Hi!
I have a code:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" >
<mx:Script>
<![CDATA[
private function myPrivateFunction(param:Object):void{
}
public function myPublicFunction(param:Object):void{
}
]]>
</mx:Script>
<mx:DataGrid id="dgGris" dataProvider="{mydp}" >
<mx:columns>
<mx:DataGridColumn headerText="HEAD" dataField="item">
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{myItemFunction()}">
<mx:Script>
<![CDATA[
private function myItemFunction():void{
//Call from here to myPrivateFunction or myPublicFunction
}
]]>
</mx:Script>
</mx:Label>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>

How do I call a function (myPrivateFunction or myPublicFunction) from
the myItemFunction? Application.application. myPrivateFunction - do
not want to use.
Thank you.

Manik

unread,
Sep 12, 2009, 11:44:24 PM9/12/09
to Flex India Community
Hi McRain,

You can do it by calling ...

<mx:Script>

<![CDATA[

private function myItemFunction():void{

outerDocument.myPublicFunction(data);
}
]]
>
</
mx:Script>


REMEMBER: Function you want to call must be decalred public. You can
not call any other scoped functions from item renderer. Reason being,
we define define itemrenderer as a component and that makes it a
separate document differring from the one in which we have grid. So
only public members of your root mxml can be accessed in itemrendrer
using outerDocument variable.

manish sankhe

unread,
Sep 13, 2009, 7:32:27 AM9/13/09
to flex_...@googlegroups.com
dispatch custom event on main application form your component and in handler of that custom event(which would reside in application) call myPrivateFunction( ).

Subeesh Arakkan

unread,
Sep 13, 2009, 2:16:33 AM9/13/09
to flex_...@googlegroups.com
Hi,

You can only call the public function .

Use the outerDocument keyword. So the item renderer script will be
something like this.

private function myItemFunction():void{
//Call from here to myPrivateFunction or myPublicFunctio
outerDocument. myPublicFunction(param);
}

Regards
Subeesh

Ravi Mishra

unread,
Sep 14, 2009, 2:14:49 AM9/14/09
to Flex India Community
Hi McRain,

You can write a custom event setting its bubble value true by default.
Then dispatch this event from your itemRenderer and then listen
(attach a listener function which will be the function you want to
call) the same event on the application or the component where you are
using itemRenderers.

HTH,

-Ravi
http://achieveravi.blogspot.com

Arindam Mojumder

unread,
Sep 14, 2009, 5:41:53 AM9/14/09
to flex_...@googlegroups.com
Application.application. myPrivateFunction. This is the easiest way to call the root function. Otherwise you have to use eventDispatcher.
As per my knowledge for simple case it is better to use Application.application. myPrivateFunction than dispatch event.
If you got any other way please share with us.


2009/9/14 Ravi Mishra <ravi.a...@gmail.com>



--
@rindam

McRain

unread,
Sep 14, 2009, 4:37:19 AM9/14/09
to Flex India Community
Thank you all for your help

Hemanth Kumar T.S

unread,
Sep 14, 2009, 8:08:56 PM9/14/09
to flex_...@googlegroups.com
Hi,
 
Here I've created a sample for this itemrenderer calling the function that exists in main appln. ( using outerdocument)
check out the example
 
Thanks,
Hemanth

Reply all
Reply to author
Forward
0 new messages