Popups in Flex Using PureMVC

I have recently developed a Flex upload component using PureMVC. The component is based on a TitleWindow and displayed as a popup window. I hit a small obstacle involving Mediator registration which was due to the upload component instance not being created until I call the createPopUp() method from the PopUpManager class. The solution (thanks Cliff) came from this helpful post in the PureMVC forum (thanks daniele) and here is some of the code snippets from my application that got things running:

PopManager.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class PopManager extends PopUpManager
  {
      public static function openPopUpWindow( ComponentClass:Class, MediatorClass:Class ):void
      {
          var window:IFlexDisplayObject = PopUpManager.createPopUp( Application.application as Sprite, ComponentClass, true );
      
          ApplicationFacade.getInstance().registerMediator( new MediatorClass( window ) );
          PopUpManager.centerPopUp( window );
      }
      
      public static function closePopUpWindow( window:IFlexDisplayObject, mediatorName:String ):void
      {
          PopUpManager.removePopUp( window );
          ApplicationFacade.getInstance().removeMediator( mediatorName );
      }
      
  }

I have a CanvasStage.mxml component which holds a button which when clicked dispatches an Event to its mediator and opens the popup window.

CanvasStageMediator.as

1
2
3
4
private function onOpen( e:Event ):void
      {
          PopManager.openPopUpWindow( UploadForm, UploadFormMediator );
      }

The upload component is UploadForm.mxml with the TitleWindow default close button dispatching an Event to the UploadEventMediator calling the below method.

UploadFormMediator.as

1
2
3
4
5
6
public static const NAME:String = 'UploadFormMediator';

private function onClose( e:Event ):void
      {
          PopManager.closePopUpWindow( uploadForm, NAME );
      }

Comments