Archive for March, 2009

Mar 04 2009

Using PopupManager in Flex

Published by 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