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
-
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
-
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
-
public static const NAME:String = 'UploadFormMediator';
-
-
private function onClose( e:Event ):void
-
{
-
PopManager.closePopUpWindow( uploadForm, NAME );
-
}

6 Comments
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?
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/
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!
Thanks for the pointers. I read a lot of it. Seems like I should start by taking a closer look at PureMVC.
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. ,
Thank you. This example helped me solve my problem. Great insight into PureMVC too. Thanks!!
4 Trackbacks
[...] Flex PopUps and PMVC [...]
[...] Flex PopUps and PMVC [...]
[...] 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 [...]
[...] 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 [...]