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.

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.
click="outerDocument.myFunction();"
So the outerDocument reference to call the function on the containing page saves the day!!! cool…


27 Comments
Well done.. just encountered this problem. Like you say simple solution, but one not easy to find.
Cheers…
Will
Haha, I got the same email, tried the same thing and hit the same wall.
Would have been great if Adobe had actually included an example of this in their sample app.
Just had exactly this issue with my own code – thanks for the solution.
great.. Thank You.. Just have this issue… thanks for the solution
Just to add that ‘myFunction’ obviously now cannot be private.
Many thanks for posting this! I was pulling my hair out until I came across this
var websites: Array = [
{label:"Yahoo", data:"http://www.yahoo.com"},
{label:"Google", data:"http://www.google.com"},
{label:"Hello-World", data:"http://www.hello-world.com"}
];
cboLinks.dataProvider = new DataProvider(websites);
cboLinks.addEventListener(Event.CHANGE, linktoPage);
function linktoPage(event:Event): void {
var site: URLRequest = new URLRequest();
site.url = cboLinks.selectedItem.data;
navigateToURL(site);
}
I also get error 1180 for that which is lol calling to undefined methoddddd. Is it a similar problem? Guessing now…but anyone know?
the Data Provider part is what is getting me that error
Any thoughts on how to pass data to the outerDocument function? click=”outerDocument.myFunction(data.foo);” doesn’t seem to work and click=”outerDocument.myFunction({data.foo});” doesn’t compile.
Just had the exact same problem..
thx for the info
Any thoughts on how to pass data to the outerDocument function? click=”outerDocument.myFunction(data.foo);” doesn’t seem to work and click=”outerDocument.myFunction({data.foo});” doesn’t compile.
I would love to know the answer to this too
Hi Nikos,
Where are you pulling in data.foo from?
Look here at this example I have just built for you, it shows a String being passed to the function in the outer document and then output into a Label text field below, view source is enabled.
HTH,
Simon
http://www.nutrixinteractive.com/apps/grid_example/GridTest.html
Hello All,
Got a similar problem but my ItemRenderer is another component. Therefore the outerDocument.myFunc(); did not work. But I was lucky to guess the solution. If your ItemRenderer is another component, then the below works just fine.
click=”parentDocument.myFunc();”
Cheers,
D.
Thanks Doruk Eker for the gr8 may to use parentDocument.myFunction() method,
For other please make sure that myFunction() is a public function, otherwise you will get a runtime error.
Excellent
Ahh, thanks! Who wouldve thunk?
Blessing on your head!!! ))))
it’s a shame that they don’t talk about this kind of problems when making video tutorials (((
Hi guys,
thanks sooo much, even to Nigel!!!
Thanks – that solved my issue.
THANK YOU THANK YOU. This saved my bacon.
Thanks a lot for this article, been searching for a solution for ages, and thanks to Doruk for your solution with external components, I can now continue my project properly
Excellent solution my friends.
thanks a lot ¡¡¡
You Rock!
I was searching all over for why this was happening.
Thanks!
Me too! Thanks
@Tom @Nikos: Make sure the methods you’re calling are marked as public. private and protected won’t cut it.
Thanks man, just what I needed.
These are just the kind of stupid problems that make one dream about quitting the whole scene after a few hours of debugging
thanks!
One Trackback
[...] via: nutrixinteractive [...]