Thanks for your answer. I forgot to write that the
GameEvent.RETRIEVE_ALL_BUTTONS is already dispatched in the
onRegister/initialize method of the GameMediator.
GameEvent(GameEvent.PLAY_SIMONS_TURN)); runs an other
PlaySimonsTurnCommand that pushes the MusicButton by sending an
event. The corresponding MusicButtonMediator is listen to the
context addContextListener(MusicButtonEvent.PUSH, pushButton,
MusicButtonEvent); for that Event.
But as I wrote before, the MusicButtonMediator is created to late
so the MusicButtonEvent.PUSH from Simons turn has no effect.
So I think the best solution may be to wait/listen until all
MusicButtonMediators are instanciated and than doing the first
So, as far as I understood you need to catch an event in a
mediator which is still not initialized, because its view is not
added on the stage. What if you catch that event in a command then
add the view and then dispatch another event.
Good point. I thought it's not the best way to add an context
event listener in a command.
I've extended the BaseActor with an addContextListener and
removeContextListener method, dispatch an event in the
MusicButtonMediator.initialize() method and catch this event by the
RetrieveAllMusicButtonsCommand. If all mediators have dispatched
their events the counter is zero and the GameEvent is dispatched
for further actions.
So here is my current solution:
public class RetrieveAllMusicButtonsCommand extends BaseActor
public var buttons:MusicButtonModel;
private var _counter:uint;
public function execute():void
_counter = buttons.buttons.length;
addContextListener(MusicButtonEvent.INIT_MEDIATOR_COMPLETE, initMediatorComplete, MusicButtonEvent);
for each(var vo:MusicButtonVO in buttons.buttons.source)
dispatch(new MusicButtonEvent(MusicButtonEvent.ADD, vo));
private function initMediatorComplete(event:MusicButtonEvent):void
if(_counter == 0)
removeContextListener(MusicButtonEvent.INIT_MEDIATOR_COMPLETE, initMediatorComplete, MusicButtonEvent);
Do you have any tip how to handle/structure all the events and
their listeners? I mean, the events can be dispatched from nearly
every class of the framework. And (context) event listener can be
defined in the config class, mediators and commands. So in a larger
project it will be very difficult to watch the application flow and
know the places where an event comes from and goes to.