Recently ran into a problem with Robotlegs due to my lack of experience with it. I was creating views dynamically at runtime and intended to automatically register their mediators via mediator.mapView in my context. However, the app just didn’t seem to hook the mediator to my view despite the mediator being created successfully.

After some googling, I found this piece of lifesaving advice – With Flex, a mediator’s onRegister() hook will only be called after creationComplete. So, the mediator gets created as soon as the view component lands on stage, but onRegister() only gets called when the view component dispatches creationComplete. With plain as3, onRegister() gets called sooner (immediately after the component is added to the stage).

Therefore, if your dynamic view needs to hit the database to populate some UI elements once it’s been added to the stage, you should register the event listeners in the onRegister() method of your listener and dispatch that event from your view (not your mediator) at the end of the onRegister() method. This approach is for those who want to go with an entirely async event driven design or the case where other views in your application need to respond to the creation of your new view, in which case the onRegister() method would dispatch an event to the context bus to alert all registered mediators.