3 Replies Latest reply on Jul 19, 2006 2:52 PM by BlueRealm

    Referencing a popup

    BlueRealm
      I'm creating a popup when a menu item is selected. How do i reference the popup after its created? If the menu item is selected again i would like to just set the focus instead of recreating a new popup of the same thing. Is there away to do this?

      if(POPUP EXISTS){
      PopUpManager.bringToFront(POPUP);
      }else{
      var popUpWindow:TitleWindow = new TitleWindow();
      popUpWindow.title = "test";
      PopUpManager.addPopUp(popUpWindow, appStack, false);
      PopUpManager.centerPopUp(popUpWindow);
      }
        • 1. Re: Referencing a popup
          mac_martine Level 1
          Just use the name of the variable you used to create the window.
          In your case, its 'popUpWindow'

          So once you've created it:
          var popUpWindow:TitleWindow = new TitleWindow();

          you access it with popUpWindow.method()
          or
          PopUpManager.bringToFront(popUpWindow);
          • 2. Referencing a popup
            BlueRealm Level 1
            I understand that. But i dont know how to reference the popUpWindow.


            This example opens up new popups everytime you click the button. I'm trying to figure out a way to check to see if the popup is present or not and if it is then create a new one else bring the one thats open to the front. So basically if you click the test1 button twice it shouldnt load a new popup it should just focus that one in front. If you close it and click the button again it should reopen it.

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
            <mx:Script>
            <![CDATA[
            import mx.containers.TitleWindow;
            import mx.controls.Alert;
            import mx.managers.PopUpManager;
            import mx.managers.PopUpManagerChildList;


            private function menuHandler(menu:Button):void {
            function clear():void{
            PopUpManager.removePopUp(popUpWindow);
            }

            var popUpWindow:TitleWindow;
            popUpWindow = new TitleWindow();
            popUpWindow.title = menu.label;
            popUpWindow.height = 250;
            popUpWindow.width = 250;

            popUpWindow.addEventListener('close', clear);
            popUpWindow.showCloseButton = true;

            PopUpManager.addPopUp(popUpWindow, this, false);
            PopUpManager.centerPopUp(popUpWindow);


            }

            ]]>
            </mx:Script>
            <mx:Button x="77" y="149" label="Test1" id="Test1" click="menuHandler(Test1)"/>
            <mx:Button x="142" y="149" label="Test2" id="Test2" click="menuHandler(Test2)"/>

            </mx:Canvas>

            So what i'm tring to get is a way to referrence the current created popups so i can do a condition

            such as:

            private function menuHandler(menu:Button):void {
            function clear():void{
            PopUpManager.removePopUp(popUpWindow);
            }


            if(PATHTO.popUpWindow != null){
            PopUpManager.bringToFront(popUpWindow);
            }else{
            var popUpWindow:TitleWindow;

            popUpWindow = new TitleWindow();
            popUpWindow.title = menu.label;
            popUpWindow.height = 250;
            popUpWindow.width = 250;

            popUpWindow.addEventListener('close', clear);
            popUpWindow.showCloseButton = true;

            PopUpManager.addPopUp(popUpWindow, this, false);
            PopUpManager.centerPopUp(popUpWindow);
            }

            }
            • 3. Re: Referencing a popup
              BlueRealm Level 1
              I figured it out....

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
              <mx:Script>
              <![CDATA[
              import mx.core.IFlexDisplayObject;
              import mx.containers.TitleWindow;
              import mx.controls.Alert;
              import mx.managers.PopUpManager;
              import mx.managers.PopUpManagerChildList;

              private function menuHandler(menu:Button):void {

              var popUpWindow:TitleWindow

              var newName:String = menu.label+'1';

              if (this.systemManager.getChildByName(newName) != null){
              PopUpManager.bringToFront(this.systemManager.getChildByName(newName) as IFlexDisplayObject);
              }else{
              function clear():void{
              PopUpManager.removePopUp(popUpWindow);
              }
              popUpWindow = new TitleWindow();
              popUpWindow.title = menu.label;
              popUpWindow.name = newName;
              popUpWindow.height = 250
              popUpWindow.width = 250
              popUpWindow.addEventListener('close', clear);
              popUpWindow.showCloseButton = true;
              PopUpManager.addPopUp(popUpWindow, this, false);
              PopUpManager.centerPopUp(popUpWindow);
              }



              }
              ]]>
              </mx:Script>
              <mx:Button x="77" y="149" label="Test1" id="Test1" click="menuHandler(Test1)"/>
              <mx:Button x="142" y="149" label="Test2" id="Test2" click="menuHandler(Test2)"/>

              </mx:Canvas>