Monday, April 4, 2011

Quick way to invoke pop up window

In my last post (LINK) I showed you how to invoke a pop up window from your app. I did this by creating an instance of PopUpWindow class in my main app and then center it on current DisplayObject. I want to show you simpler and more robust way to achieve that.

In PopUpWindow you just have to add a new static function:

public static function createPopUp():void
{
  var popUp:PopUpWindow = new PopUpWindow();
  PopUpManager.addPopUp(popUp, FlexGlobals.topLevelApplication as DisplayObject, true);
  PopUpManager.centerPopUp(popUp);
}

This would be something like pseudo-contructor for PopUpWIndow. Now in your main app you can invoke a pop up window just like that:

PopUpWindow.createPopUp();

This will create a pop up that is always centered in the main app. If you want to center your window on a any DisplayObject, you can change slightly above function:

public static function createPopUp(displayObject:DisplayObject):void
{
  var popUp:PopUpWindow = new PopUpWindow();
  PopUpManager.addPopUp(popUp, displayObject, true);
  PopUpManager.centerPopUp(popUp);
}

This function works almost like a contructor, so you can make some calculations in it or just pass data to pop up window.

No comments:

Post a Comment