6 Replies Latest reply on May 21, 2009 5:53 AM by _Natasha_

    I need help with my popup.

    scorptique

      Hello. This popup application is working. However the problem is if the popup is already popped up, i am still able to press the button to open the same popup. So I can just continously open up the same pop-up, overlapping one another. I want to be able to only allow one pop-up at a time. I tried dispatching event but I think i got the codes wrong. Im trying boolean and add/remove event listener now but I cant get it right as _root does work. Someone please help me. thanks.

       

      ------------------------------------------------------------------------------------------ ------------------------------------------------------------------

       

      //From the main application

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      creationComplete="openSimpleWindow()">
      <mx:Script>
      <![CDATA[
      import mx.managers.PopUpManager;
      import windows.SimplePopupWindow;
      private var simpleWindow:Object;
      private var popUpOpen:Boolean = false;

       

      private function openPopUp():void{
          if (!popUpOpen)
          btn.addEventListener(MouseEvent.CLICK, openPopUp);
          simpleWindow = PopUpManager.createPopUp(this,windows.SimplePopupWindow,false);
          popUpOpen = true;
      }


      ]]>
      </mx:Script>
          <mx:Button label="Button" id="btn" click="openPopUp()"/>
      </mx:Application>

       

      ------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------

       

      //From the popup application

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" >
          <mx:Label x="10" y="10" text="Testing testing"/>
          <mx:Button x="10" y="36" label="close" id="close_btn" click="closeMe()"/>
          <mx:Script>
              <![CDATA[
                  import mx.managers.PopUpManager;
                  private function closeMe():void
                  {
                  PopUpManager.removePopUp(this);
                  //_root.btn.addEventListener(MouseEvent.CLICK, _root.openPopUp);        

                 }

       

              ]]>
          </mx:Script>
      </mx:TitleWindow>

        • 1. Re: I need help with my popup.
          _Natasha_ Level 4

          Hi,

          private var simpleWindow:Object;
          private var popUpOpen:Boolean = false;

           

          private function openPopUp():void{
              if (!popUpOpen)

          {

          // you don't need this string, you've already add listener
          // -->   btn.addEventListener(MouseEvent.CLICK, openPopUp);

          // you can disable button

          btn.enabled = false;
              simpleWindow = PopUpManager.createPopUp(this,windows.SimplePopupWindow,false);

          simpleWindow.addEventListener(CloseEvent.CLOSE, onCloseWindow);
              popUpOpen = true;

          }
          }

          private function onCloseWindow(event:CloseEvent):void

          {

          popUpOpen = false;

          btn.enabled = true;

          PopUpManager.removePopUp(simpleWindow);

          simpleWindow = null;

          }

           

          // in popup

                    private function closeMe():void

                      {

                         this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
                      }

          • 2. Re: I need help with my popup.
            scorptique Level 1

            Thanks for the reply. However I had this error message.

             

            1118: Implicit coercion of a value with static type Object to a possibly unrelated type mx.core:IFlexDisplayObject.

             

            I dont understand what it means. It was pointing to "PopUpManager.removePopUp(simpleWindow);" in the onCloseWindow function.

            • 3. Re: I need help with my popup.
              _Natasha_ Level 4

              change

               

              private var simpleWindow:SimplePopupWindow;

              • 4. Re: I need help with my popup.
                scorptique Level 1

                Now it says:

                 

                1118: Implicit coercion of a value with static type mx.core:IFlexDisplayObject to a possibly unrelated type windows:SimplePopupWindow.  

                 

                It was pointing to "simpleWindow = PopUpManager.createPopUp(this,windows.SimplePopupWindow,false);" in the openPopUp function =S Sorry i dont understand these error messages. Just started learning flex 3 weeks ago.

                • 5. Re: I need help with my popup.
                  _Natasha_ Level 4

                  There are two variants:

                  var simpleWindow:IFlexDisplayObject;

                  or

                  simpleWindow = SimplePopupWindow(PopUpManager.createPopUp(this,windows.SimplePopupWindow,false));

                   

                  The first is better.

                  • 6. Re: I need help with my popup.
                    scorptique Level 1

                    It works! THANKS!