4 Replies Latest reply on Jan 29, 2011 10:22 AM by kiran7881

    Unable to Pass Parameters to Custom PopUp Window ??

    kiran7881 Level 1

      Hi

       

      Please help in passing Data from an MXML  file to my POPUp window mxml

       

      MainMXML File :


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" horizontalAlign="left" verticalAlign="middle">
          <mx:Script>
              <![CDATA[
                  import mx.events.FlexMouseEvent;
                  import MyPopUpWindow;
                  import mx.events.FlexEvent;
                  import mx.managers.PopUpManager;
                  private var popup:MyPopUpWindow;
                  private function openPopUpWindow():void {
                      popup = PopUpManager.createPopUp(this,MyPopUpWindow,true) as MyPopUpWindow;
                      PopUpManager.centerPopUp(popup);
                  }
              ]]>
          </mx:Script>
         
          <mx:Canvas width="288" height="177">
             <mx:HBox id="jai">
              <mx:Image source="images/canvas.png" visible="true" height="100%" width="100%"/>
              <mx:Label id="kkk" text="Ravi"/>
              <mx:Button label="Edit" click="openPopUpWindow()"/>
          </mx:HBox>
          </mx:Canvas>   
         
      </mx:Application>

       

      =======

       

      MyPopuWindow.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- custom popup window component - comps/MyPopUpWindow.mxml -->
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
              layout="vertical"
              title="My Custom PopUp Window"
              showCloseButton="true"
              close="PopUpManager.removePopUp(this)">
              <mx:Script>
                  <![CDATA[
                      import mx.managers.PopUpManager;
                  ]]>
              </mx:Script>
              <mx:Form>
                  <mx:FormHeading label="User"/>
                  <mx:FormItem label="Username">
                      <mx:TextInput id="un" />
                  </mx:FormItem>
              </mx:Form>
             
      </mx:TitleWindow>

       

      On to the TextInput i need to have the value of Label kkk value . I tried with inline  binding but it didn't worked

       

      <mx:TextInput id="un"  text= {kkk.text}/> isn't working . please help

        • 1. Re: Unable to Pass Parameters to Custom PopUp Window ??
          Phoenix_Guru Level 1

          Take a public bindable variable in the popup window. Bind the text input to this variable. After creating the pop up (just after createPopup call when you have got the reference of the window, set the value of that public variable to kkk.text, then ur usual centerPopup call. that should be it!

          Sorry for being lazy and not posting any code.

           

          If this answer was helpful, please mark it as such!

           

          Thanks,

          Saurabh

          • 2. Re: Unable to Pass Parameters to Custom PopUp Window ??
            kiran7881 Level 1

            Thanks for the idea, I did this way . Its working but worried as what happens if its not present inside Main Appliction.mxml

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" horizontalAlign="left" verticalAlign="middle">
                <mx:Script>
                    <![CDATA[
                        import mx.events.FlexMouseEvent;
                        import MyPopUpWindow;
                        import mx.events.FlexEvent;
                        import mx.managers.PopUpManager;
                        private var popup:MyPopUpWindow;
                       
                        [Bindable]
                        public var str:String ;
                       
                        private function openPopUpWindow():void {
                            popup = PopUpManager.createPopUp(this,MyPopUpWindow,true) as MyPopUpWindow;
                            str = kkk.text;
                            PopUpManager.centerPopUp(popup);
                        }
                    ]]>
                </mx:Script>
               
                <mx:Canvas width="288" height="177">
                   <mx:HBox id="jai">
                    <mx:Image source="images/canvas.png" visible="true" height="100%" width="100%"/>
                    <mx:Label id="kkk"  text="Pavan"/>
                    <mx:Button label="Edit" click="openPopUpWindow()"/>
                </mx:HBox>
                </mx:Canvas>   
               
            </mx:Application>

             

            ========

            <?xml version="1.0" encoding="utf-8"?>
            <!-- custom popup window component - comps/MyPopUpWindow.mxml -->
            <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="vertical"
                    title="My Custom PopUp Window"
                    showCloseButton="true"
                    close="PopUpManager.removePopUp(this)">
                    <mx:Script>
                        <![CDATA[
                            import mx.core.Application;
                            import mx.managers.PopUpManager;
                        ]]>
                    </mx:Script>
                    <mx:Form>
                        <mx:FormHeading label="User"/>
                        <mx:FormItem label="Username">
                            <mx:TextInput id="un" text="{Application.application.str}"/>
                        </mx:FormItem>
                    </mx:Form>
                   
            </mx:TitleWindow>

             

            please sugest correct approach .

            • 3. Re: Unable to Pass Parameters to Custom PopUp Window ??
              saisri2k2 Level 4

              ther is another way to add the popup see below

               

              var popup:SomePopup = new SomePopup();
                             popup.somePublicVariable = "somevalue";//here the somePublicVariable is the setter/getter
                             PopUpManager.addPopUp(popup,this,false);
                             
              

              • 4. Re: Unable to Pass Parameters to Custom PopUp Window ??
                kiran7881 Level 1

                Ya , this will work in any condition 

                 

                Thanks .