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

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

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

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

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

UploadFormMediator.as

Actionscript:
  1. public static const NAME:String = 'UploadFormMediator';
  2.  
  3. private function onClose( e:Event ):void
  4.         {
  5.             PopManager.closePopUpWindow( uploadForm, NAME );
  6.         }

This entry was posted in Flex, PureMVC and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments

  1. Posted November 26, 2007 at 11:01 pm | Permalink

    Interesting.

    I am developing flex myself, and have not yet felt the need enough to introduce something like PureMVC, Caingorm or the likes.

    Now, I see in your post, that had I been using PureMVC, I would not have been able to simply use PopUpManager out of the box, but think something else into it.

    What is your thoughts on this? How have your value been on using PureMVC when compared to stuff like this in this blog entry, where you have to do extra, because of PureMVC?

    I guess what I am asking is: Is it worth it? To use an application framework like PureMVC. How much benefit is there?

  2. Posted November 26, 2007 at 11:26 pm | Permalink

    Oh man, yeh its definitely worth it, big time. Out the box your right things are pretty str8 forward and I can see how some looking at this post may think hmmm bit of wrangling there, why bother? That trivial obstacle I came across was solved sooo quick, was documented on the frameworks website and once I had resolved I can use that principle throughout any future project in Flex. Reusibility makes it worth it.

    This particular app was for a much bigger project which was constructed using PureMVC by another developer. I was asked to build the uploader (obviously having to use PureMVC) which I built and plugged into the existing project without having any knowledge whatsoever of the projects structure or purpose. Out of the larger projects copious amount of classes I only touched (I think) 2 to integrate the uploader. Future add ons to this project would be just as simple and anyone with knowledge of the framwork would know how to work their way around the system, none of this "erm well I put this there I think and it does this and that"!

    Honestly, its a must do for developers in my opinion!

    READ: http://www.nutrixinteractive.com/blog/?p=65 and google for opinions, its the way to the next level...

    Here are some links man, its huge so this is just a couple:

    http://www.asserttrue.com/articles/2007/10/17/silvafug-application-frameworks-presentation
    http://flexblog.faratasystems.com/?p=246
    http://www.slideshare.net/joeflash/introduction-to-design-patterns-for-flash-and-flex-by-joseph-balderson
    http://www.ericfeminella.com/blog/2006/10/01/design-patterns-in-as3/

  3. Bart Veenstra
    Posted November 27, 2007 at 8:55 am | Permalink

    I am currently using the PureMVC framework in my application and I really like the way that it decouples everything from each other.

    I had the same probmem with popup windows and I solved it by adding a startup command for the panel itself, which registered the mediators for the panel.

    But this method looks a lot cleaner because now my mxml files won't kwow about PureMVC at all. Thanks!

  4. Posted November 27, 2007 at 9:59 pm | Permalink

    Thanks for the pointers. I read a lot of it. Seems like I should start by taking a closer look at PureMVC.

  5. Posted October 23, 2009 at 1:28 am | Permalink

    The model presented here reflects the character of the discipline: it identifies the types of questions software engineers find interesting, the types of results we produce in answering those questions, and the types of evi- dence that we use to evaluate the results. ,

  6. Posted November 7, 2009 at 1:48 pm | Permalink

    Thank you. This example helped me solve my problem. Great insight into PureMVC too. Thanks!!

4 Trackbacks

  1. By PureMVC Links « The Algorithmist on January 22, 2008 at 2:51 pm

    [...] Flex PopUps and PMVC [...]

  2. [...] Flex PopUps and PMVC [...]

  3. [...] out for notifications in a mediator thats registered using the PopManager class I detailed here http://www.nutrixinteractive.com/blog/?p=76 be aware that the mediator may not be registered when the notifications are being [...]

  4. By Handling Popup Logic in PureMVC *Update* on February 8, 2009 at 4:55 pm

    [...] of my logic in handling popups in a Flex application using PureMVC. If you refer to my previous post you will see that I have a PopManager that extends PopUpManager and the core logic to handle [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>