Code to display your popup:
var popup:MyPopup = new popup:MyPopup(); popup.addEventListener(CloseEvent.CLOSE, function(evt) { PopUpManager.removePopUp(popup); }); PopUpManager.addPopUp(popup, this, true);
Inside your MyPopup class, you will have a button to close the popup. Just move the click event to post the CLOSE event:
<s:Button Label="X" click="dispatchEvent(new CloseEvent(CloseEvent.CLOSE));" />
I prefer this mechanism so that the MyPopup object calls PopUpManger.removePopUp (as @Fank points out) because it binds the MyPopup component to the PopUpManager , which I don't like. I would prefer the MyPopup user to decide how to use the component.
Honestly, these are two very similar mechanisms for fulfilling the same ultimate goal.
source share