Flex & PopUpManagerPlus

Posted: 28/01/11

An image of Flex & PopUpManagerPlus

This trivial wrapper for mx.managers.PopUpManager allows you monitor the number of active pop-ups in your Flex app, as well as a convenience method to removeAllPopUps()

package

{

import flash.display.DisplayObject;

import mx.core.IFlexDisplayObject;

import mx.core.IFlexModuleFactory;

import mx.managers.PopUpManager;

public class PopManagerPlus

{

private static var _popUps:Vector.<IFlexDisplayObject> = new Vector.<IFlexDisplayObject>();

public function PopManagerPlus()

{}

public static function removeAllPopUps() :void

{

while( _popUps.length > 0 )

{

PopUpManager.removePopUp( _popUps.pop() );

}

}

public static function addPopUp( window:IFlexDisplayObject, parent:DisplayObject, modal:Boolean=false, childList:String=null, moduleFactory:IFlexModuleFactory=null ) :void

{

_popUps.push( window );

PopUpManager.addPopUp( window, parent, modal, childList, moduleFactory );

}

public static function removePopUp( popUp:IFlexDisplayObject ) :void

{

_popUps.splice( _popUps.indexOf( popUp ), 1 );

PopUpManager.removePopUp( popUp );

}

public static function bringToFront( popUp:IFlexDisplayObject ) :void

{

PopUpManager.bringToFront( popUp );

}

public static function centerPopUp( popUp:IFlexDisplayObject ) :void

{

PopUpManager.centerPopUp( popUp );

}

public static function get numPopUps() :int

{

return _popUps.length;

}

}

}

This code has been tested with Flex 3.2 through to Flex 4.5, running in Flash Player 10.0 and up.

Keywords for this post: flex, popupmanager, pop-up, actionscript 3, IFlexDisplayObject