Mar 04 2009

Using PopupManager in Flex

Published by at 10:13 am under Flex

PopupManager is another utility class in Flex which i really love to use as often as i can. With big projects when you need to lay views on top of other views and things like that it really comes in handy.

 

Within the Flex framework this class is also used by some of components like Alert, Combobox. If you take a look at the Audiolife widget i have developed, this class has really saved my life there. The merchant descriptions, album descriptions are mxml components displayed using PopupManager. 

 

Any class which implements the Interface IFlexDisplayObject can be added and removed using PopUpManager, this is how i achieve it. 

 

var albumDetails:AlbumDetails = new AlbumDetails();

//create the class which needs to be added this is mxml component inheriting Canvas

PopUpManager.addPopUp(albumDetails,model.popUpHolder);

//add it on top of everything and position it within the holder, it just needs a parent display object

model.currPopUp = albumDetails as IFlexDisplayObject;

//store a reference so that it can be removed from anywhere in the application

PopUpManager.centerPopUp(albumDetails)

albumDetails.dataVal = itemXML;

//show the details inside this class

albumDetails.y = model.popUpY;

//position the new popup wherever we want

albumDetails.width = model.popUpWidth;

//the width of this view

albumDetails.height = model.popUpHeight;

//the height of this view

 

I have a singleton model which stores the reference to this class  so this popup can be removed from anywhere within the application by using PopUpManager.removePopUp(model.currPopUp);

 

It works great and is very convenient way of handling views, instead of doing visibility of certain components etc. This will also improve the performance of your application since you are adding and removing classes at runtime instead of keeping them in memory and not just messing with visibility.

 

2 responses so far

2 Responses to “Using PopupManager in Flex”

  1. Rogeron 06 Jul 2011 at 10:10 am

    Hi, this is a good article. But I want to learn how to use singleton model to store the reference to my own class, would you please give me some examples or other references? I really need it to popup an alert message anywhere and anytime when needed in my mobile project. Thanks!!

  2. Nayanon 13 Jul 2011 at 11:19 am

    i am not sure if popup manager is the best way to show alerts, you should be using the native alert, there are components people have made for it as well.

    why create your own when others have already done the work :)

Trackback URI | Comments RSS

Leave a Reply