4 Replies Latest reply on Feb 28, 2008 6:21 AM by peterent

    Please help with ViewStack(Newbie here)

    Thom21
      Hello, this is probably a very simple question fo most of you, but I just started learning Flex and have been trying different things. So any help would be greatly appreciated.

      What I'm doing now is creating a few simple visual components with back and next buttons and I want to use viewstack, particularly selectedindex, which is what someone recommended, to cycle though them in the oder I like.

      What are the recommended steps to follow to do this?
        • 1. Re: Please help with ViewStack(Newbie here)
          Thom21 Level 1
          I e-wrote my problem in a clearer way to see if I can get any help...

          I'm creating a few simple visual components with back and next buttons and I want to use the viewstack, particularly selectedindex, which is what someone recommended, to cycle though them in the order I like.

          I can access the button id from the child inside the viewstack, for example:

          <viewstack>
          <comp:component01 nextButton:""/>
          </viewstack>

          But how do I tell nextButton, which is the button id in the component to go to another component?
          • 2. Re: Please help with ViewStack(Newbie here)
            peterent Level 2
            You could try something like this:

            <mx:ViewStack id="stack">
            <mx:Canvas label="First Child">
            .....<mx:Button label="Next" click="stack.selectedIndex=1" />
            </mx:Canvas>
            <mx:Canvas label="Second">
            .....<mx:Button label="Back" click="stack.selectedIndex=0"/>
            .....<mx:Button label="Next" click="stack.selectedIndex=2"/>
            </mx:Canvas>
            ...
            </mx:ViewStack>

            That's not a very programmatic way to it, but it gets the job done. What I would do is put the Next and Back buttons outside of the ViewStack and then you do it a bit more programmatically:

            <mx:Button label="Next">
            <mx:click><![CDATA[
            if( stack.selectedIndex+1 < stack.numChildren ) stack.selectedIndex = stack.selectedIndex +1;
            ]]></mx:click>
            </mx:Button>
            • 3. Re: Please help with ViewStack(Newbie here)
              Thom21 Level 1
              Thank you very much for the reply. It did help.

              What if I wanted o have an skip button in just a couple of he components hat I wanted to help me skip a step that maybe one or two screens ahead?
              • 4. Re: Please help with ViewStack(Newbie here)
                peterent Level 2
                OK. Let's say this is one child of the ViewStack:

                <mx:Canvas label="Some Child" id="someChild" >
                ....<mx:Button label="Skip 2">
                .......<mx:click><![CDATA[
                ............var index:int = stack.getChildIndex(someChild);
                ............index += 2;
                ............// make sure the index is not going to be out of bounds
                ............if( index >= stack.numChildren ) index -= 2;
                ............stack.selectedIndex = index;
                .......]]></mx:click>
                ....</mx:Button>

                HTH