2 Replies Latest reply on Jun 28, 2007 8:28 AM by levancho

    Change view states using a TabBar control

    shawnytoe
      Hi,

      I'm new to using Adobe Flex and was wondering how to change multiple view states using a TabBar control. What I've done so far is create four view states. My purpose is to show a different state based on which tab is selected in the TabBar. Setting the TabBar's currentState property doesn't seem to work in this scenario. Is there some way I can set each tab's currentState property?

      Thanks,
      Roshawn
        • 1. Re: Change view states using a TabBar control
          Clark_Kent101 Level 1
          Roshawn,

          The TabBar works like it should if its connected to a ViewStack. In the ViewStack you would need to insert however much canvas' each with its own label. The label of each canvas in the ViewStack will correspond with the names of the buttons on the TabBar (assuming you haven't already done this). Here is an example:

          --------------------------------------------
          <mx:TabBar dataProvider="{viewstack1}">
          </mx:TabBar>

          <mx:ViewStack id="viewstack1" width="200" height="200">
          <mx:Canvas label="View 1" width="100%" height="100%">

          <mx:Text text="State 1" />

          </mx:Canvas>
          <mx:Canvas label="View 2" width="100%" height="100%">

          <mx:Text text="State 2" />

          </mx:Canvas>
          <mx:Canvas label="View 3" width="100%" height="100%">

          <mx:Text text="State 3" />

          </mx:Canvas>
          </mx:ViewStack>
          --------------------------------------------

          You'd obviously need to insert whatever needs to be inserted into each Canvas.

          Hope this helps,

          - Tony
          • 2. Re: Change view states using a TabBar control
            levancho Level 3
            the problem is with little confusion between States Vs Stack
            as Tony outlines TabBar needs to be glued to ViewStack (which is a Kind of Invisible Container Object) which is not a State.
            State is another concept of Flex where you can define different states for same container and based on some event occurance , transition from state to state.
            (for example if you have a Rich Text Editor, you can define two states Advanced and Simple and switching between them basically adds or removes some additional editing buttons from the container etc ... )
            I doubt you can natively glue states to TabBar but if States (and not Stacks) is how you want to display different pages of the app, the only way I know(and probably there might be other ways) you need to change state manauly for example off of onClick event of the Tabbar or something similar.