This content has been marked as final. Show 2 replies
The problem is that you're trying to go outside the chain of command, so to speak. If I'm correctly understanding what you're attempting, then my suggestion is that you raise an event from your 'homepage' component, and listen for that event in your application.
So, in the homepage component, call dispatchEvent(new Event("doWhatever")), and then in your application you can do homepage.addEventListener("doWhatever", yourAction).
If you want to do it all from MXML, remember to add an [Event(name="doWhatever", type="flash.events.Event")] at the top of your homepage component - this will allow you to just use doWhatever="..." in your MXML.
There are 2 approaches to take here which are very similar. The first approach uses the "targeting phase" of the ActionScript 3 event system. Since you are using a Button you know that it has a "click" event. But did you know that you can place that event handler on any parent of the Button? For example, in your Main application file you could do this:
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:comps="components.*" layout="vertical" click="handleClickEvent(event)" >
When the Button on the home_page is picked, the click event will go upward through the object heirarchy until it finds a handler. If you don't have a handler on the Button itself, then its parent is tried, if there's no handler there, then its parent is tried, etc.
If you were to place the event handler on the Application itself, EVERY click event might possibly wind up there, so you need to look at the event itself to see which object sent the event.
You might also be able to do this:
<comps:homePage id="home_page" label="Home Page" click="handleClickEvent(event)" />
but only if the homePage component is capable of dispatching a click event itself. You have to check the Flex documentation for that.
See About the Event Flow in the Flex documentation for more details about the event flow.
The second option is have your homePage component dispatch a custom event. You create a new class dervied from an event class, such as flash.event.Event, and when the Button in the homePage is picked, dispatch your custom event instead. To do that, you'll need to register the event in the homePage component using Metadata:
then you can do:
<comps:homePage id="home_page" label="Home Page" myCustomEvent="handleMyEvent(event)"/>
Those are the 2 recommended ways to communicate between components.