4 Replies Latest reply on Mar 19, 2007 3:53 PM by wahben

    Viewstates via comboboxes

    wahben Level 1
      Hi all. Newbie to flex, but getting more accustomed each and every day. Got a perplexing problem that i cannot for the life of me figure out. I know in all the tutorials, you can change viewstates via a button control. Can anyhyone offer any guidance on changing view states based on comboboxes? Any insight is greatly appreciated!
        • 1. Re: Viewstates via comboboxes
          hi i've done something similar on my application and this is what i did.

          inside the actions script i created an array to hold my 2 states which were database management and a scheduler state.

          [Bindable] private var viewState:Array =["Database Management","Scheduler"];

          then i create a function that is called everytime the user selects any of the two states on the combobox

          private function ChangeState():void {
          if (cb_view.selectedItem == "Database Management") {

          currentState=''; //this is my base state
          } else if (cb_view.selectedItem == "Scheduler") {
          to call this function simply i simply did this:

          <mx:ComboBox id="cb_view" styleName="myCombo" dataProvider="{viewState}" change="ChangeState()" x="10" y="10"></mx:ComboBox>

          hope this helps

          • 2. Re: Viewstates via comboboxes
            wahben Level 1
            africanshox- THANKS!!!! This is a lifesaver...Again, thanks!
            • 3. Re: Viewstates via comboboxes
              Josh Johnson Level 1
              You could also expand this to accommodate more than two states by embedding the state names into the array objects. The array would look like this:

              <object label="Foo" state="foo" />
              <object label="Bar" state="bar" />
              <object label="Foobar" state="foobar" />

              And then your actionscript for the change would just have to pull the value for 'state' from the selected object, and push it into the currentState. Hope this helps.
              • 4. Re: Viewstates via comboboxes
                wahben Level 1
                Thanks! Before I had no options....thanks!