12 Replies Latest reply on Dec 28, 2008 12:14 PM by savyasachi

    Nested ViewStacks

    savyasachi
      My application uses nested ViewStacks. The First child in the outer ViewStack V1 is a Canvas and contains a DataGrid. Each record in the datagrid represent a Supervisor in a department. A click on a row in the datagrid brings the ViewStack 2 and the first child displays the employee reporting to the supervisor selected above. Basically, I am calling my dataservice and passing the supervisor id as a parameter to my fill method. I am calling the fill() method in the creationComplete event handler for the viewStack2. This is working for the first time.

      However, if I go back to ViewStack1 and select a different supervisor, I am still seeing the employee for the previous supervisor and creationComplete event handler for the ViewStack2 is not being called again.

      How do I address this issue? Have been struggling with this since couple of days. Try to dispatch event, but this event is not reaching the ViewStack2 at all. Appreciate the help.

      Thanks.
        • 1. Re: Nested ViewStacks
          rtalton Level 4
          The creationComplete event will only run the first time a component is created, so once ViewStack2 is created, you're done with that event.

          You just need a different event to do all this. I'd suggest the DataGrid click handler to call your dataservice, then use the data service's resultHandler to process the data and switch to ViewStack2.

          DataGrid click event-->click handler requests data-->resultHandler assigns data to component in ViewStack2, and then makes ViewStack2 active.
          • 2. Re: Nested ViewStacks
            savyasachi Level 1
            Thanks for your input rtalton. I am not finding an easy way to access or reference the child component inside the inner ViewStack from the outer ViewStack. I am getting the below error:

            1119: Access of possibly undefined property innerVwStId through a reference with static type mx.containers:ViewStack.
            • 3. Re: Nested ViewStacks
              Level 7

              "savyasachi" <webforumsuser@macromedia.com> wrote in message
              news:gj6nqq$m1d$1@forums.macromedia.com...
              > My application uses nested ViewStacks. The First child in the outer
              > ViewStack
              > V1 is a Canvas and contains a DataGrid. Each record in the datagrid
              > represent a
              > Supervisor in a department. A click on a row in the datagrid brings the
              > ViewStack 2 and the first child displays the employee reporting to the
              > supervisor selected above. Basically, I am calling my dataservice and
              > passing
              > the supervisor id as a parameter to my fill method. I am calling the
              > fill()
              > method in the creationComplete event handler for the viewStack2. This is
              > working for the first time.

              Try using updateComplete.

              HTH;
              Amy


              • 4. Re: Nested ViewStacks
                rtalton Level 4
                savyasachi , could you post some code for us to see? I don't know what "innerVwStId " is.
                • 5. Nested ViewStacks
                  savyasachi Level 1
                  Amy, No luck!!!

                  updateComplete event also gets fired only one time similar to creationComplete.

                  • 6. Re: Nested ViewStacks
                    rtalton Level 4
                    Good, you're making progress with understanding Flex events!
                    Check the help docs for information on each of these events you're considering using.
                    • 7. Nested ViewStacks
                      savyasachi Level 1
                      'innerVwStId' is the id of the inner ViewStack.

                      Here is the code:
                      //This function handles the row selection event for the datagrid containing supervisors
                      //This dataGrid is part of the first child in the main ViewStack
                      private function mgrSelectionHandler(event:ListEvent):void
                      {
                      model.globals.mgrId = mgrsGrid.selectedItem.id;

                      mainVwStack.selectedIndex = Globals.MAINVW_MGRDETAILS;

                      mainVwStack.mgrDetails.innerVwStId.employeeVw.refill();
                      }



                      //This is the function which is in the 'employeeVw'child view of the inner ViewStack
                      //which is where I am calling the fill() method when a different manager id is selected
                      //in the mainViewStack
                      public function refill():void
                      {
                      dsEmployee.fill(arEmps, model.globals.mgrId);
                      }
                      • 8. Re: Nested ViewStacks
                        ntsiii Level 3
                        Use the result event from the data service call.
                        Tracy
                        • 9. Re: Nested ViewStacks
                          ntsiii Level 3
                          Also, with Viewstack, be aware of deferred instantiation issues.
                          Tracy
                          • 10. Re: Nested ViewStacks
                            Level 7

                            "savyasachi" <webforumsuser@macromedia.com> wrote in message
                            news:gj8cgu$nei$1@forums.macromedia.com...
                            > No luck!!!
                            >
                            > updateComplete event also gets fired only one time similar to
                            > creationComplete.
                            >

                            That's odd, since I use it that way in my ViewStack code.


                            • 11. Re: Nested ViewStacks
                              savyasachi Level 1
                              Tracy,

                              I don't think I understood your solution completely. Please forgive me for my ignorance.

                              The dataService is inside the child of the inner ViewStack and I am trying to find a way to call the fill method whenever the row selection in the main ViewStack changes. Did you mean by moving the dataService to the main ViewStack and point the result handler to a function defined inside the innerViewStack?

                              Could you please elaborate.

                              Appreciate it.
                              • 12. Re: Nested ViewStacks
                                savyasachi Level 1
                                Don't know if this is the effective way of accomplishing this or not, but found a work around for this constraint:

                                I am storing the reference to the employeeVw of the inner ViewStack in the global variables container. This variable will be initialized the first time the employeeVw is created. And whenever a new Supervisor Id is selected in the main ViewStack, I am calling the employeeVw.refill() function which calls the dataService and then switching the view to the employeeVw.

                                Thank you all for your help. Please let me know if you see any performance issues with this.

                                Have a great day.