5 Replies Latest reply on Aug 5, 2007 8:15 PM by skramx

    ComboBox value -> ViewStack id=

    skramx
      My goal is to not have to use a switch statement.. and therefore be as dynamic as possible...

      [Bindable] private var models:Array = ["tasks","users","bugs"];
      public function changeViewStackModel():void
      { //this.modelViewStack.selectedChild=users; //works
      //this.modelViewStack.selectedChild="users"; //does not work
      //this.modelViewStack.selectedChild=this.modelsCombo.selectedItem; //does not work
      switch(modelsCombo.selectedItem){
      case "tasks": modelViewStack.selectedChild=tasks; break;
      case "users": modelViewStack.selectedChild=users; break;
      case "bugs": modelViewStack.selectedChild=bugs; break;
      }
      }

      MXML...
      <mx:ComboBox id="modelsCombo" dataProvider="{models}" selectedIndex="0" change="changeViewStackModel()"/>
      <mx:ViewStack x="29.25" y="55" id="modelViewStack" width="90%" height="200">
      <mx:Canvas id="tasks" label="Tasks"><mx:Label text="Tasks stack view!!"/></mx:Canvas>
      <mx:Canvas id="users" label="Users"><mx:Label text="Users stack view!!"/></mx:Canvas>
      <mx:Canvas id="bugs" label="Bugs"><mx:Label text="Bugs stack view!!"/></mx:Canvas>
      </mx:ViewStack>

      Any ideas? I've been trying to figure this out for a long time!
        • 1. Re: ComboBox value -&gt; ViewStack id=
          chris.huston.t10 Level 3
          There are two ways that I can think to do this. The simplest way is like this:

          public function changeViewStackModel():void {
          modelViewStack.selectedIndex = modelsCombo.selectedIndex;
          }

          The above method assumes that your comboBox item order and viewStack order are the same. If this will not be the case, then I would make an ArrayCollection of objects where each object specified the label and viewStack index.

          import mx.collections.ArrayCollection;
          [Bindable] private var models:ArrayCollection = new ArrayCollection([{label:"Tasks", vsIndex:0},{label:"Users", vsIndex:1},{label:"Bugs", vsIndex:2}]);
          public function changeViewStackModel():void {
          modelViewStack.selectedIndex = modelsCombo.selectedItem.vsIndex;
          }


          Vygo

          • 2. Re: ComboBox value -&gt; ViewStack id=
            skramx Level 1
            Thank you very much. I actually figured it out a couple hours ago. Sorry I didn't update the post. I do have another question though. I am using a remoteobject with weborb so my data from the server comes to me in a ArrayCollection. It is called <Model>Controller_index. In mx:datagrid, I want to dynamically set the dataProvider for the current model (modelsCombo.selectedItem).

            I appreciate any/all help

            • 3. Re: ComboBox value -&gt; ViewStack id=
              chris.huston.t10 Level 3
              This question is probably best handled in a new thread, but basically you just need to specify a result function for your call to webOrb and set the dataProvider there.

              function weborbResult(evt:ResultEvent):void {
              dg.dataProvider = evt.result; //sets dataGrid data provider to the ArrayCollection returned from the remote call.
              }

              Vygo
              • 4. Re: ComboBox value -&gt; ViewStack id=
                skramx Level 1
                OKay, good idea. I guess I only need to store an array of the current model's data.

                The other thing is.. I want to set the headerText neatly. I know I will need to hardcode this.. what is the best practice in this case?
                • 5. Re: ComboBox value -&gt; ViewStack id=
                  skramx Level 1
                  OKay, good idea. I guess I only need to store an array of the current model's data.

                  The other thing is.. I want to set the headerText neatly. I know I will need to hardcode this.. what is the best practice in this case?