4 Replies Latest reply on Sep 14, 2009 8:23 AM by Ned Murphy

    Terrible comboBox Trouble - can't assign label and data

    daveCph

      Hey and thanks for looking...

       

      I have a comboBox which I try to populate via PHP/MySql.

       

      the AS:

      var result_lv:LoadVars = new LoadVars();
      result_lv.load("http://MyWebSite.com/flashData.php?ID=3");

       

      result_lv.onLoad = function(success:Boolean) {

          var tstVar:String = String(_root.result_lv.allCountrysVar) ;
          var my_array:Array = tstVar.split("splitHere");
          for (var i = 0; i<my_array.length; i++) {
              var bob:Array = my_array[i].split(",")

             _root.comboBox.addItem(bob);
          }

       

       

      I have no problem getting and manipulating the array from PHP:

      ("allCountrysVar=data:2 , label:Andora splitHere  data:3 , label:Austria splitHere  data:4 , label:Denmark splitHere )

       

      but when I look at the comboBox it displays:

      label:Andora,  data:2
        label:Austria,  data:3
        label:Denmark,  data:4

       

      as labels

       

      and not just:

      Andora
      Austria
      Denmark

       

      and I am truly at a loss to see what I do wrong.Your help will realy be appreciated

       

      Best Regard

       

      Dave

        • 1. Re: Terrible comboBox Trouble - can't assign label and data
          kglad Adobe Community Professional & MVP

          bob is an array of strings, not objects that contain strings.  for example, one item you're adding is:

           

          "data:2 , label:Andora"

           

          instead of what you want to add:

           

          {data:2,label:"Andora"}

           

           

          you need to further parse the data before assigning  to your combobox.

          1 person found this helpful
          • 2. Re: Terrible comboBox Trouble - can't assign label and data
            Ned Murphy Adobe Community Professional & MVP

            PArt of the problem is expecting string information to be treated as variable assignments (label:... data:...).  If the data is as you show it in the file, then I think what you show as displaying in the combocox is backwards, because the data element should be first.

             

            When you get to the stage where you are trying to add bob into the combobox you have an array with two elements...

             

            bob[0] is the data string... "data:etc..."   and

            bob[1] is the label string... "label:etc..."

             

            But you are adding bob, which essentially puts the whole array of strings in as the label element

             

            If you were to do something more like...

             

            _root.comboBox.addItem( {label:bob[1], data:bob[0]} );

             

            You would be a bit closer to getting what you intend, except at this stage each of those items still has the "data:" and "label:" text part of the string in each element of the bob array.  So what you really wanna do is either not include those in the data string to begin with, or strip them out of the strings as part of the processing.

             

            I don't know if you can use eval() to make the string "data:etc" be interpretted as part of an object... at least I can't think of a way off the top of my head.

            • 3. Re: Terrible comboBox Trouble - can't assign label and data
              daveCph Level 1

              Many thanks for the help, both of you. All is behaving as desiered.

               

              Dave