3 Replies Latest reply on Jul 3, 2008 11:34 AM by ntsiii

    datagrid actionscript coding question

    Mongolian Beef Level 1
      Being new to AS3, I encountered a coding issue when creating my DataGrid that I'm not sure I understand. Initially my code looked like this:

      ############################################
      var dg:DataGrid = new DataGrid();
      var dgc:DataGridColumn

      for (var i:int = 0; i < books.length(); i++) {
      dgc = new DataGridColumn();
      dgc.headerText = columnName;
      dg.columns.push(dgc);
      }

      ....
      this.addChild(dg);
      ######################################


      The code above does not work. However, when I added the datagridcolumns dynamically in a temp. array, it worked. The working code is shown below:

      ########################################
      var dg:DataGrid = new DataGrid();
      var dgc:DataGridColumn
      var aColumnsNew:Array = dg.columns

      for (var i:int = 0; i < books.length(); i++) {
      dgc = new DataGridColumn();
      dgc.headerText = fcolumnName;
      aColumnsNew.push(dgc);
      }

      dg.columns = aColumnsNew;
      ...
      this.addChild(dg);
      ######################################## Text