7 Replies Latest reply on Mar 14, 2007 7:23 AM by Lasci

    Multiple combo boxes

    Lasci
      Hi all,

      New to this forum. Hoping someone might be able to help or point me in the right direction. I`m trying to use three combo boxes, with each combination of choices taking the user to a different frame. Is this possible? Any hints of where to start?

      Many thanks in advance!
        • 1. Re: Multiple combo boxes
          mclem
          combo boxes have the on (change) event and you can access what the user selected from a combo box using the selectedItem object. The selectedItem object is an object with two properties, label and data. An example of accessing the selectedItem is listed below.

          you can then check to see if the other 2 combo boxes are set and if so then based on the 3 setting of the box use gotoAndStop() to jump to a new frame based on the users selection.

          • 2. Re: Multiple combo boxes
            Lasci Level 1
            Thanks for your reply. I have now got as far as being able to tell which item has been selected from two combo boxes, but can`t seem to use them outside of this function. I tried declaring as global variables but still can`t get it to work.

            Heres my code:

            var myComboBox1:mx.controls.ComboBox;

            myComboBox1.removeAll();
            myComboBox1.addItem("--Choose--", "Choose");
            myComboBox1.addItem("one", "1");
            myComboBox1.addItem("ten", "10");
            myComboBox1.addItem("twenty", "20")

            myComboBox2.removeAll();
            myComboBox2.addItem("--Choose--", "Choose");
            myComboBox2.addItem("a", "a1");
            myComboBox2.addItem("b", "b10");
            myComboBox2.addItem("c", "c20")


            //Check taking the correct value from combo box 1
            myComboBox1.addEventListener("change", doChange1);
            function doChange1 (evt1){
            trace ("Combo box 1 " + evt1.target.value);
            _global.varResult_1=evt1.target.value
            }

            //Check taking the correct value from combo box 2
            myComboBox2.addEventListener("change", doChange2);
            function doChange2 (evt2){
            trace ("Combo box 2 " + evt2.target.value);
            varResult_2=evt2.target.value
            }

            //Try to choose which frame to go to depending on both combo boxes
            function checkResult(){
            //varResult_1=myComboBox1.value
            //varResult_2=myComboBox2.value
            if((_global.varResult_1==10)&(_global.varResult_2==b10)){
            gotoAndStop(10)
            }
            }

            function doChange(evt1) {
            trace("Value changed to 1" + _global.varResult_1);
            trace("Value changed to 2" + evt2.target.value);
            checkResult()
            }

            Can anyone give me any hints of where I am going wrong or where to look for help?

            Thanks again
            • 3. Re: Multiple combo boxes
              BorosAdam Level 1
              elements in a comboBox have 'data' and 'label' properties. try to use them instead of 'value'... in your code for example this line: myComboBox2.addItem("a", "a1"); adds a new item to the comboBox. properties for the added item are: label->"a", data->"a1" ... there is no 'value' property!
              and if i can advice something you don't need two listeners for this since they do totally the same thing. that's what the 'target' is for in the listener, right? let's say you have 'combo1' and 'combo2' then you can have one listener for both, something like this:

              • 4. Re: Multiple combo boxes
                BorosAdam Level 1
                on the other hand you don't need listeners for this at all! :) you can access the values (label and data!!!) of the selected item in a comboBox without any listeners like this: comboBoxInstance.selectedItem.label
                so, you can write all the stuff in one function like this:

                • 5. Re: Multiple combo boxes
                  Lasci Level 1
                  Thanks, have tried method 2 as it looks much simpler, however can`t seem to make it work, can you suggest anything?

                  Code is as follows:

                  var myComboBox1:mx.controls.ComboBox;

                  myComboBox1.removeAll();
                  myComboBox1.addItem("--Choose--", "Choose");
                  myComboBox1.addItem("one", "1");
                  myComboBox1.addItem("ten", "10");
                  myComboBox1.addItem("twenty", "20")

                  myComboBox2.removeAll();
                  myComboBox2.addItem("--Choose--", "Choose");
                  myComboBox2.addItem("a", "a1");
                  myComboBox2.addItem("b", "b10");
                  myComboBox2.addItem("c", "c20")

                  function customGoto(){
                  goto1 = myComboBox1.selectedItem.data;
                  goto2 = myComboBox2.selectedItem.data;
                  //and now you can do all the stuff with sel1 and sel2 like the following
                  if (goto1 == "1" && goto2 == "a1"){
                  gotoAndStop(1);
                  }else if (goto1 == "10" && goto2 == "b10"){
                  gotoAndStop(10);
                  }
                  }

                  Thanks in advance again!
                  • 6. Re: Multiple combo boxes
                    BorosAdam Level 1
                    strange, it works for me... probably you make some other mistake. download my fla from the url below. i hope it helps. ;)
                    twoComboExample.fla
                    • 7. Re: Multiple combo boxes
                      Lasci Level 1
                      Got it working! Yey! Thanks for all your help! Code is here just incase anyones interested...