With built-in modal support, popup windows can demand the user's attention or force interaction when necessary. This is possible because windows below a modal popup window cannot receive mouse events until a modal popup window is dismissed.
The PopUpManager class is used to manage popup windows in Flex. You can create, center and remove popup windows by using the static methods of the PopUpManager class.
public static function addPopUp(window:IFlexDisplayObject, parent:DisplayObject, modal:Boolean = false, childList:String = null):voidcreatePopUp()
public static function createPopUp(parent:DisplayObject, className:Class, modal:Boolean = false, childList:String = null):IFlexDisplayObjectcenterPopUp()
public static function centerPopUp(popUp:IFlexDisplayObject):voidremovePopUp()
public static function removePopUp(popUp:IFlexDisplayObject):void
Creating a popup windowFlex provides two distinct, yet very similar, methods for creating a popup window and placing it on a layer above all other visible windows – addPopUp() and createPopUp(). The difference between each method is subtle and determining which to use is mostly a matter of preference.
Note: Adobe documentation states that "using the addPopUp() method may be preferable to using the createPopUp() method if you have to pop up a simple dialog box that is never used elsewhere."Looking closely at each method signature (addPopUp & createPopUp), the difference dictates how to use the method rather than when to use it. (or so it seems)
Here are some guidelines I tend to follow:
|Requires a popup window instance as an argument||Yes||No|
|Returns a value that can be stored in a variable||No||Yes|
If you want to create a quick and dirty simple popup window that you don't plan to reuse, use addPopUp().
If reuse of a popup window is a priority, use createPopUp() and store the returned object in a variable for later use.
Centering a popup windowA popup window can be centered in relation to any DisplayObject. When creating a popup window using addPopUp() or createPopUp(), it is important to understand that the parameter named "parent" (datatyped as DisplayObject) will be used to determine the reference point for centering a popup window. In most cases, you’ll want a popup window to be centered over the Application.
In the previous example, notice that the DisplayObject used to center the popup window was this. In this case, this refers to the Application container, and therefore, the popup window was centered nicely over the Application. In many cases this will not refer to the Application container (i.e. inside custom components). When opening a popup window from within a custom component, use the following code to ensure the popup window is centered over the Application container and not the custom component.
Removing a popup windowOnce our popup window has been created, displayed and optionally centered, there are a couple of options for removing it from display.
1. A parent removes a popup window from display
2. A popup window removes itself from display
I hope that gives you some ideas about how to use PopUpManager & TitleWindow in your Flex apps. Have fun!