2 Replies Latest reply on Feb 7, 2008 4:19 PM by ntsiii

    traversing an array in a forloop

    Tikis_Mikis Level 1
      OK, I have posted this like two times total in both this and another Flex forum - its gotten to the point that I cant even find my original posts because they get no replies!! So here I am trying again and will give a sample array so that you can see what I am trying to do

      Here is my array:

      Code:
      [settings] => Array
      (
      [set_color] => Array
      (
      [label] => "Color"
      [values] => "black, grey, white"
      [input_type] => "combobox"
      )

      [set_text] => Array
      (
      [label] => "Name"
      [values] => ""
      [input_type] => "text"
      )

      [set_rank] => Array
      (
      [label] => "Rank"
      [values] => "1-10"
      [input_type] => "combobox"
      )
      )

      This value is pulled from a DB and its returned by PHP in the associative array above. As you can see I am trying to dynamically add form element to my app depending on what values are in the "settings" index. I need to loop through each of array settings main key values (set_color, set_text, set_rank) and in turn loop through each of the values within each key (lable, values, input_type). By the input_type value I determine what type of component to create.

      The array has a set depth like that above - for example the inner key "values" will NEVER point to a new array. so The settings array has two levels.

      HOW DO I TRAVERSE THROUGH THIS ARRAY?

      This is NOT WORKING:

      ActionScript Code:
      for (var key:String in selectedFilterData.settings) {
      Alert.show(selectedFilterData.settings[key].label);
      }


      or this:
      ActionScript Code:
      if (selectedFilterData.settings.length > 0) {
      Alert.show("success");
      }

      please help me....