Calling an ActionScript3 Method From a Item Render in Flex

After receiving an email from Adobe detailing an application to load XML data into a DataGrid (written by Christoph Rooms) I hit a wall when trying to call a method in my actionscript. The DataGrid column had an mx:Image contained within mx:Component in an itemRenderer so that a little icon image can be displayed according to the xml data.

code

When I edited click=”…” and inserted my reference to an actionscript method I encountered:

1180: Call to a possibly undefined method myMethod

So I scoured the net, help files and saw ways of tackling this issue, some involving (if I understood them correctly) creating a custom event class then calling a function which is situated in an mx:Script tag which itself is within the mx:Image tag ?:)?

Anyway, the solution was in time found (thanks to my flex bible) and it is irritatingly simple. It turns out as always its a scope issue, the mx:Component tag defines a new scope where the local scope of the item renderer is defined by the MXML code.

1
click="outerDocument.myFunction();"

So the outerDocument reference to call the function on the containing page saves the day!!! cool…

Comments