Thursday, 22 September 2011

Self Closed Custom Alert Using Title Wndow.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="Alert_PopUpManager_removePopUp_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
         import mx.controls.Label;
         import mx.containers.TitleWindow;
         import mx.controls.Alert;
            import mx.events.CloseEvent;
          

            private var alrt:TitleWindow=new TitleWindow();
            private var alrtTimer:Timer;
private var newlbl:Label=new Label;
            private function init():void {
                alrtTimer = new Timer(5000, 1);
                alrt.title="Self Closed Alert";
                alrt.showCloseButton=true;
                alrt.addEventListener(CloseEvent.CLOSE,alrt_close)
                newlbl.text="This is custom alert which will be self closed";
                alrt.addChild(newlbl);
                alrtTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeAlert);
            }

            private function showAlert():void {
                alrtTimer.reset();
                alrtTimer.start();
                btn1.enabled=false;
                this.addChild(alrt);
            }

            private function alrt_close(evt:CloseEvent):void {
                alrtTimer.stop();
                btn1.enabled=true;
                this.removeChild(alrt);
                }

            private function removeAlert(evt:TimerEvent):void {
               this.removeChild(alrt);
               btn1.enabled=true;
            }
        ]]>
    </mx:Script>

    <mx:Button id="btn1" label="CLICK ME" click="showAlert();" />
  
</mx:Application>


No comments:

Post a Comment