PDA

View Full Version : communication between custom classes


freddyk
09-18-2009, 03:28 AM
Hi

Is there a simple way to communicate with the root of a Flex 3 application? Something like the _root call used to be in past versions of ActionScript.

If you have one custom mxml class inside another custom class how can I call functions in the main application from the custom class that is called from within another custom class.

I have a scrolling list that is made up of item renderers that are a custom class. When the user clicks the items contained within the item renders I want to send data to the main application. If the class is directly under the main application I can use the mx:Metadata tag to create a custom event which works great. I just can't seem to get it to work if the custom event is sent from a custom component that is being used to render items in another custom component.

I have heard that maybe the 'bubbles' feature can help but I have not been able to figure out how to take advantage of it.

This has really been killing forward progress. Any links, threads, or tips would really be appreciated.

Thanks

freddyk
09-18-2009, 04:29 AM
I have had a breakthrough on the issue. Of course it is so easy that I want to strangle myself.

In Flex 3 I can use the following code to populate a text box at the root of the application:
mx.core.Application.application.forChange.text = "Boo";

Of course I am late to the game because this simple solution has already been depreciated by Flex 4. Now I am told to use:
FlexGlobals.topLevelApplication

But I have not figured out how to get that to work. Any tips?

I know that this route is not as good as using custom events but in the case of my components within components issue I will take what I can get.

freddyk
09-18-2009, 04:36 AM
Here it is:
mx.core.FlexGlobals.topLevelApplication.forChange. text = "Hell Yea";

So this is still not best practices but I need the solution. In most cases using the mx:Metadata tag to create a custom event is best.

Now if I could only figure out how to do the same thing from within a .swf file the rest would be a cake walk. Any Ideas? How to write a Flash swf button that can make a similar call to:
mx.core.FlexGlobals.topLevelApplication.forChange. text = "Hell Yea";