2 Replies Latest reply on Jun 26, 2010 10:18 AM by kabhatta

    Re: dynamic creation of associative arrays


      Hi, I need some advise on the following problem. I'm developing code that allows me to copy & paste a spreadsheet into a TextArea and parse the pasted text to dynamically generate a DataGrid. I assume that the first line of the text contains the headers for each column, parse the line and dynamically generate the columns for the DataGrid. Now I need a way to generate each rown of the DataGrid from the rest of the lines. The issue I am struggling with (new to Flex) is the following. I believe I have to create an associative array of the following form:


      var asArray:Object = {col1:"value1", col2:"value2", etc}


      The problem is that all Column names are in one array and each value is stored in another array. How do I dynamically create a construct that will

      lead me to represent one row in a DataGrid as described in asArray? In other words, is there a way to dynamically generate a statement as the one above?


      Appreciate your help!


        • 1. Re: dynamic creation of associative arrays
          MikisMM Level 2

          If I understand correctly you manage to parse all your data to two types of arrays:

          var columns:Array = {"column1", "column2", ...}

          var rowValues:Array = {<value1>, <value2>", ...}

          So as you can see I assume that each value in rowValues array has corrseponding column name in columns array. So you can construct your "associative array" (actually thats just a simple object) like this:

          var rowObject:Object = new Object();

          for (var i:int = 0; i < rowValues.length; i++) {

          rowObject[colums[i]] = rowValues[i];


          The core of the loop is the third line and the use of square brackets on an object.

          • 2. Re: dynamic creation of associative arrays
            kabhatta Level 1

            Thanks for the quick and correct response, appreciate it.