Mike Orth – Booya!

Flex, Actionscript

TitleWindow Subclass for Easily Handling Popups

Typically if you choose to use a TitleWindow, odds are you’re going to add it with the PopupManager and use the Close button. So rather than having to always set that up and add listeners for the CloseEvent, use this extended class PopupBase. It’s used the same as TitleWindow, declared in actionscript

var popup:PopupBase = new PopupBase();

or mxml,

<containers:PopupBase />

but by default it:

  • sets showCloseButton=true
  • sets a listener for CloseEvent
  • removes the popup when Close button is pressed

You can override the onClose handler to add different functionality.

package containers
{
    import mx.containers.TitleWindow;
    import mx.events.CloseEvent;
    import mx.managers.PopUpManager;
   
    public class PopupBase extends TitleWindow
    {
        public function PopupBase()
        {
            showCloseButton = true;
            addEventListener(CloseEvent.CLOSE, onClose);
        }
       
        protected function onClose(event:CloseEvent):void
        {
            PopUpManager.removePopUp(this);
        }
    }
}
No comments

No comments yet. Be the first.

Leave a reply

Spam Protection by WP-SpamFree

Mexico

Google Tracking Code