Flex popup

I am creating a modal canvas popup on the parent page. When I close the popup, how do we get a notification on the parent screen that the popup has just been closed. Any event for this?

+4
source share
3 answers

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.

+5
source

Yes there is: I prefer to use the Popupmanager:

Your popup: There is a close button for calling the internal function eg.closeme

 private function closeMe () :void { PopUpManager.removePopUp(this); } 

in your parent, you will open PopUp as follows:

 private function openPopup () :void { var helpWindow:TitleWindow = TitleWindow(PopUpManager.createPopUp(this,MyTitleWindow,fale)); helpWindow.addEventListener(CloseEvent.CLOSE, onClose); } protected function onClose (event:CloseEvent) :void { PopUpManager.removePopUp (TitleWindow(event.currentTarget)); } 

My TitleWindow is the name of your pop-up class extended by TitleWindow.

BR Frank

0
source

Along with Brian's answer, be sure to turn off the event listener. If you leave an event handler in your main application listening for an event from a child, the child will not be garbage collected because something is still referencing it. This is a common memory leak problem.

 popup.addEventListener(CloseEvent.CLOSE, popup_CloseHandler); private function popup_CloseHandler(event:CloseEvent):void{ event.target.removeEventListener(CloseEvent.CLOSE, popup_CloseHandler); PopUpManager.removePopUp(popup); } 

Here's a great post on Flex memory management if you want to delve into that.

http://blogagic.com/163/flex-memory-management-and-memory-leaks

0
source

Source: https://habr.com/ru/post/1379498/


All Articles