6 Replies Latest reply on Jul 6, 2009 9:41 AM by radekdymacz

    passing variables between popups

    radekdymacz

      I'm trying to pass variables from one popup to another . It works fien if I pass bvariable from main aplication as soon as I'm trying to pass variable from popup to popup window it doesnt work Here is what I'm trying ro do :

       

      That works fine

      main.mxml

       

      private function launchMoreInfo():void {
                      var win:view = PopUpManager.createPopUp(this, view, true) as view;
                    //
                    
                     win.AccountNum = list1.selectedItem.accountNum;
                     win.user = user;

       

                  }

       

      but if I try to pass variables to popup created from popup component it doesnt' work

      view.mxml

       

      private function dsclientevents():void {
                      var win2:view = PopUpManager.createPopUp(this, dsclienteventlog, true) as view;
                    //
                    
                    win2.AccountNum = 'test';

       

                  }

       

       

      AccountNum is declared in  dsclienteventlog.mxml

       

       

       

      Is it possible to pass variables between popups ?

       

       

      I would apreciate your help

       

      Thanks

        • 1. Re: passing variables between popups
          Madhav Subedi Level 4

          as accountNum is declared in dsclienteventlog.mxml, you cannot access it through win which is an instance of view.

           

          for such, i would make an extra class, lets say controller, and put a static variable there, say acctnumber.

           

          now you can modify this variable from one popup and access the modified variable from another popup.

          • 2. Re: passing variables between popups
            radekdymacz Level 1

            yes but is it possible to pass variables between popups ?

            basically I have datagrid in one popup and want to display another grid in popup window based on data selected in first datagrid

            It would be easier if I can pass this variables from one popup to another as I'm making a call to soap to retrive data for second popup

            based on data selected in datagrid I hope I make  sense sorry  english is not my first language

            I've tried with parentAplication.datagridID from second popup but that doesn't seem to work

            I really apraciate your help

            Thanks

            • 3. Re: passing variables between popups
              *Prashant Shelke* Level 4

              You can create var parent:Object; in each popUp window & before it will popUp from its parent set it as

              childPopUp.parent = this;


              For 1st popUp parent object will contains mainApp.mxml reference.

              • 4. Re: passing variables between popups
                rgadiparthi Level 2

                use dataGrid itemClick event to pass the data.

                 

                 

                try like this

                 

                your first popup datagrid

                 

                        <mx:DataGrid id="dg1" width="100%" height="100%" rowCount="5" dataProvider="{employees}" itemClick="onItemClick(event)">
                            <mx:columns>
                                <mx:DataGridColumn dataField="name" headerText="Name"/>
                                <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                                <mx:DataGridColumn dataField="email" headerText="Email"/>
                            </mx:columns>
                        </mx:DataGrid>

                 

                on itemClick we are creating another popup window and passing the data that is selected in your first popup datagrid.

                 

                 

                            private function onItemClick(event:ListEvent):void
                            {
                                var item:Object = event.currentTarget.selectedItem;
                                var win:view = PopUpManager.createPopUp(this, view, true) as view;

                                win.testData = item;
                            }

                 

                here is your view datagrid

                 

                    <mx:HBox>
                        <mx:DataGrid id="dg2" width="100%" height="100%" rowCount="5" dataProvider="{testData}" >
                            <mx:columns>
                                <mx:DataGridColumn dataField="name" headerText="Name"/>
                                <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                                <mx:DataGridColumn dataField="email" headerText="Email"/>
                            </mx:columns>
                        </mx:DataGrid>
                    </mx:HBox>

                 

                if you want to create another popup when something selected in your dg2, you can create itemClick handler to ur dg2 and proceed.

                • 5. Re: passing variables between popups
                  mk_ananth Level 1

                  Hi Friend!

                       I have faced this kind of problem and solved by using "Public static var".

                   

                  You just declare a public static variable in your Popup class. Then you can directly set value to that variable like,

                  ClassName.StaticVariableName = Value;

                   

                  In your case,

                  say PopUp2.mxml or PopUp2.as

                   

                  <script>

                       public static var m_iSelectedID:int;

                   

                       your stuff here....

                  </script>

                  =======

                   

                  In PopUp1 script:

                   

                  OnItemSelectionChange(event):void

                  {

                       PopUp2.m_iSelectedID = DatagridID.selectedItem.AccountID; // it will change the value of that variable even though the popup2 is opened.

                       your stuff here....

                  }

                   

                  Try this, I hope this will help you.

                   

                  Thanks,

                  Ananth.

                  • 6. Re: passing variables between popups
                    radekdymacz Level 1

                    Thanks for your help guys decalring variables as  public static type seems to do the trick for me

                    Thanks a lot again for swift answare