You can register and dispatch events w.r.t systemManager when you want to listen events in components/Objects which do not participate in
So dispatch event in your comp2 as systemManager.dispatchEvent(YourEvent); and in your Comp1 listen it w.r.t systemManager again..
This should just work fine for you..
Thanks for your quick reply. It works indeed.
> Is there any possibility to just listen for the event from Comp2 directly in Comp1?
Sure. You don't have to use bubbling and SystemManager. Comp1 can just register for the event from Comp2 with code like
Adobe Flex SDK Team
Thank for your reply.
I realised I could just use parentApplication.comp2.addEventListener in Comp1.
To make things short I now use the parentApplication to dispatch events and listen to them.
- parentApplication.dispatchEvent(new CustomEvent(CustomEvent.MY_EVENT));
- parentapplication.addEventListener(CustomEvent.MY_EVENT, myEventHandler);
I think this styl of event handling only gonna work if your both components are in the main mxml file only...What say if your comp1 is in main mxml
and comp2 is main mxml and say there is another component comp3 in the comp1 itself then if you are dispatching the event in the comp2 then how you
gonna listen to that event in comp3....???
I think I can just accomplish that by doing the exact same in comp3.
since it is dispatched like parentApplication.dispatchEvent(...) in comp2.
It is dispatched for parentApplication, which means I could just listen for it in another nested child or isn't that gonna work?
I wouldn't recommend using the application as a surrogate event dispatcher for a component. In general, components should dispatch their own events as part of proper object-oriented component design (unless you're using some application framework with centralized event dispatching). Any object can listen to any IEventDispatcher, as long as it has a reference to it. If you don't like having to do
in Comp1 then I recommend passing a reference-to-Comp2 to Comp1 when Comp1 is constructed. Just consider it a property of Comp1 which tells Comp1 who to listen to.
Adobe Flex SDK Team