How to Mediate a Flex Popup

Flex PopUpManager is a very handy tool for creating popup windows in an application. It provides some challenges for mediation in a Robotlegs application. The problem is that Flex creates the popup "outside" of the context view's display list. Robotlegs has no way to automatically mediate the view component. When using PopUpManger to create popups, it is necessary to manually create the mediator for the view component:

// In the class that maps the mediator:
mediatorMap.mapView( MyPopupView, MyPopupViewMediator, null, false, false ); //disable auto mediation

// In a command or mediator:
var popup:MyPopupView = new MyPopupView();
PopUpManager.addPopUp( popup, contextView ); // contextView is defined in Command
mediatorMap.createMediator( popup );

The popup is now fully mediated and ready to talk to the rest of the framework.

When the popup is closed you will need to manually remove it's mediator:

mediatorMap.removeMediator( mediator );
// OR
mediatorMap.removeMediatorByView( popup );

note: The contextView reference above is defined on the mvcs Command and Mediator classes and will be injected by the framework automatically.