5 Replies Latest reply on Jul 31, 2008 10:47 PM by masita18

    Need Help with ViewStack :(

    masita18 Level 1
      I have a titlewindow with 2 buttons. And within the titlewindow there is a viewstack. The viewstack have 2 containers. Button1 click event to switch to container1 and button2 click event to switch to container2. Each container have its own control. Container 1 have textinput and vslider. Container 2 also have textinput and vslider. I could retrieve and set the values of controls in container 1 when button1 is click using viewstack.selectedIndex=0. but am unable to set the values of the control in container 2 when button2 is clicked using viewstack.selectedIndex=1. Got this error for container2.

      Error #1009: Cannot access a property or method of a null object reference.

      Appreciate if you could kindly advise.

      if(DB.variableView == "Cont1")
      {
      varEditor.toggleBtn1.selectedIndex = 0;
      varEditor.viewstack1.selectedIndex = 0;

      varEditor.txtInitialValue1.text = DB.varInitialValue;
      }
      if(DB.variableView == "Cont2"){

      varEditor.toggleBtn1.selectedIndex = 1;
      varEditor.viewstack1.selectedIndex = 1;
      varEditor.txtInitialValue2.text = DB.varInitialValue;
      }

        • 1. Re: Need Help with ViewStack :(
          Gregory Lafrance Level 6
          You need to have IDs set for the 2 containers, and when a button is pressed use varEditor.viewstack1.selectedChild = containerID.
          • 2. Re: Setting Data on Viewstack 2nd comtainer
            Level 7

            "masita18" <webforumsuser@macromedia.com> wrote in message
            news:g6r666$cr4$1@forums.macromedia.com...
            >I have a titlewindow with 2 buttons. And within the titlewindow there is a
            > viewstack. The viewstack have 2 containers. Button1 click event to switch
            > to
            > container1 and button2 click event to switch to container2. Each container
            > have
            > its own control. Container 1 have textinput and vslider. Container 2 also
            > have
            > textinput and vslider. I could retrieve and set the values of controls in
            > container 1 when button1 is click using viewstack.selectedIndex=0. but am
            > unable to set the values of the control in container 2 when button2 is
            > clicked
            > using viewstack.selectedIndex=1. Got this error for container2.
            >
            > Error #1009: Cannot access a property or method of a null object
            > reference.
            >
            > Appreciate if you could kindly advise.
            >
            > if(DB.variableView == "Cont1")
            > {
            > varEditor.toggleBtn1.selectedIndex = 0;
            > varEditor.viewstack1.selectedIndex = 0;
            >
            > varEditor.txtInitialValue1.text = DB.varInitialValue;
            > }
            > if(DB.variableView == "Cont2"){
            >
            > varEditor.toggleBtn1.selectedIndex = 1;
            > varEditor.viewstack1.selectedIndex = 1;
            > varEditor.txtInitialValue2.text = DB.varInitialValue;
            > }

            You can either put the call to these in creationComplete of the containers
            in the ViewStack or you can set a flag on change of the ViewStack and then
            execute this code from updateDisplayList.

            HTH;

            Amy


            • 3. Re: Need Help with ViewStack :(
              dimival Level 1
              I don't think the ids will solve anything Greg. Actually the issue is the creationPolicy of the components, masita18. Flex automatically creates only the components that are visible so any component on your second container is not available until you access that container.

              One way to solve this is to change the creationPolicy of your ViewStack to "all", that way Flex will create all the components inside the viewstack, be aware that if you have tons of components your application will load slower.

              There should be other threads with your same issue around here, some of them have posts with better solutions for your issue.
              • 4. Need Help with ViewStack :(
                Gregory Lafrance Level 6
                I would think myViewstack.selectedChild = container2 would be the initial access that causes it to be initially created. I don't think in this case creationPolicy needs to be all.
                • 5. Re: Need Help with ViewStack :(
                  masita18 Level 1
                  Hi all!

                  I've tried to set the creationPolicy = "all".
                  It works perfectly fine!
                  Thank you so so much :)