4 Replies Latest reply on Aug 13, 2009 4:03 PM by alevicki

    Restrict to only one Native Window?

    alejandrorrr

      Hello everyone, im trying to create a simple twitter client as a project for getting acquainted a little bit more with AIR. So far im able to fetch the data, if i double click on a message a new Window is opened where i could reply to the user. The problem is that if i double click again on other (or the same) message another window opens. This is not the desired behavior.

       

      What would be the best way so that ONLY one reply window is open at any given time?

       

      I'm thinking:

       

      1. Disable the double click property of the list.

      2. A singleton.

       

      But im sure there must be a more "accepted" formal way of doing this.

       


      Thanks!

       

       

      Alejandro

        • 1. Re: Restrict to only one Native Window?
          alevicki Level 2

          Only create a new window if the window is not closed.

           

          So something like this

           

          var win:Window;

           

          function doubleClickHandler(event:Event):void{

               if (win == null || win.closed){

                    win = new Window();

               }

               win.setMessage(event.target);

          }

          • 2. Re: Restrict to only one Native Window?
            alejandrorrr Level 1

            Thanks for taking the time to answer, I knew there had to be an easier way, but I tried this within my project:

             

            public var sendMsg:SendSMS = new SendSMS();

             

                private function onItemDoubleClick(event:ListEvent):void {
                        if (sendMsg != null || sendMsg.closed)
                                {       
                                var sendMsg:SendSMS = new SendSMS();
                                sendMsg.height = 500;
                                sendMsg.width = 500;
                                sendMsg.tweetName = event.currentTarget.selectedItem.user;
                                sendMsg.open();
                                }
                        sendMsg.addEventListener(SendSMSEvent.ENABLE_CHANGED, handleClick);       
                 }

             

             

            But no luck? SendSMS is a <mx:Window> component, so there should be no problem there... Did i do something wrong here?

             

             

            Thanks

             

             

            Alejandor!

            • 3. Re: Restrict to only one Native Window?
              alevicki Level 2

              I had a typo when I originally posted, but your code should work if you do it like this:

               

               

              public var sendMsg:SendSMS; // don't instantiate this yet

               

                  private function onItemDoubleClick(event:ListEvent):void {
                          if (sendMsg == null || sendMsg.closed) // notice that I changed != to ==
                                  {       
                                  sendMsg = new SendSMS(); // don't declare a duplicate variable, use the variable declared outside
                                  sendMsg.height = 500;
                                  sendMsg.width = 500;
                                  sendMsg.tweetName = event.currentTarget.selectedItem.user;
                                  sendMsg.open();

                                  sendMsg.addEventListener(SendSMSEvent.ENABLE_CHANGED, handleClick);       
                                  }

                                  else

                                   {

                                       // This implies that the window is still open

               

                                       sendMsg.tweetName = event.currentTarget.selectedItem.user;

               

                                       // You'll need to make sure you are either binding to tweetName in your display, or that tweetName is actually a setter and you

                                       // modify whatever is displaying it when it is changed

                                  }

                         
                   }

              • 4. Re: Restrict to only one Native Window?
                alejandrorrr Level 1

                Thanks a Million for that snippet. It works wonderfully right now!!! I'll make sure i understand what is happening there!

                 

                 

                Again thanks a lot!!

                 

                 

                Alejandro