6 Replies Latest reply on May 12, 2009 2:47 AM by Addytoe

    Help in ComboBox

    Addytoe

      I understand that, this maybe an easy task but I cannot seem to get the logic as to how I should make it work...

       

      What I am attempting to do is to get my ComboBox to display Male or Female using a Switch but the returned data is to be M or F.

       

      I seem to getting a null reference... do I need to create an initApp and initialize the initApp to get what I am trying to do?

      Any references or guides to this problem?

       

      private function genderHandler(item:Object):void
      {
                  var sex:String = 'M';
                 var sex2:String = 'F';
                  item = genderBox.selectedItem;       
                  switch(sex)
                  {
                     case 'M':
                                  sex = String(item);
                                  genderBox.text = "Male";
                          break;
                      case 'F':
                                  sex2 = String(item);
                                  genderBox.text = "Female";
                          break;
                      default:
                                  genderBox.text = "Choose One";
                          break;
                  }
      }

       

       

      <mx:ComboBox id="genderBox" dataProvider="{('M', 'F')}" labelFunction="genderHandler" />

        • 1. Re: Help in ComboBox
          ATIF FAROOQ

          hi,

             try using this code it should work

           

                          private function genderHandler(item:Object):String

               {

           

           

                         switch(item)

                         {

                            case 'M':

                                        return "Male";

                                 break;

                             case 'F':

                                         return  "Female";

                                 break;

                             default:

                                         return "Choose One";

                                 break;

                         }

                         return ''

               }

           

                          <mx:ComboBox id="genderBox" dataProvider="{['M', 'F']}"

          labelFunction="genderHandler"  x="443" y="216" width="295"/

          1 person found this helpful
          • 2. Re: Help in ComboBox
            Addytoe Level 1

            Thanks for the help... I tried the code below and the output on the comboBox displays the female but the male does not display...

             

            Any ideas what this means??

             

            From my understanding... does this mean that I gotta make the comboBox set the male as a default selectedItem ??

             

            private function genderHandler(item:Object):String
            {
                            switch(item)
                            {
                                 case 'M':
                                                 return "Male";
                                    break;
                                case 'F':
                                                 return  "Female";
                                    break;
                                 default:
                                                return "Choose One";
                                    break;

             

                             }
              }

             

            <mx:ComboBox width="150" id="gBox" dataProvider="{('M', 'F')}" labelFunction="genderHandler" />

            • 3. Re: Help in ComboBox
              ATIF FAROOQ Level 3

              <mx:ComboBox id="genderBox" dataProvider="{('M', 'F')}"

              labelFunction="genderHandler" />

               

              here you are using parenthesis  in dataProvider="{('M', 'F')}"  you

              should use array and use Square brackets like this dataProvider="{([M',

              'F']}"

              • 4. Re: Help in ComboBox
                Addytoe Level 1

                Thanks alot for the guidance ... I have managed to get it done... Thanks alot again

                • 5. Re: Help in ComboBox
                  Addytoe Level 1

                  I hope you don't mind me asking why use square brackets? I am very new in Flex and I am still trying to understand the basics of it...

                   

                  Does the square brackets indicate it to behave like an Array?

                  • 6. Re: Help in ComboBox
                    ATIF FAROOQ Level 3

                    Yes square Brackets are Use to Define Arrays in your application perhaps its

                    a short hand for defining them.Proper method is to instantiate Array Class

                     

                    var myArray:Array=new Array()

                     

                    then u can use all methods available in Array class

                     

                    u can also initialize array like this

                     

                    var myArray:Array=['m','F'];

                    1 person found this helpful