1 Reply Latest reply on Apr 28, 2007 3:25 PM by kribot

    Data Grid and For Loop

    chriskeeler2
      I am having trouble with populating a DataGrid control from a For Loop. The For loop traces like I want, but how do I get the data into the data grid?
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" initialize="initData()">
      <mx:Script>
      <![CDATA[
      import mx.collections.*;

      public function createTimes():void {
      var theHour:uint;
      var theMin:String;
      var aORp:String;
      var timeSlots:Array = new Array();

      for (var hr:uint=7;hr<20;hr++) {
      if (hr > 12)
      {theHour = hr-12;}
      else {theHour = hr;}

      for (var min:uint=0;min <46;min+=15) {
      if (min == 0) {
      theMin = "00";
      } else {
      theMin = String(min);
      }
      if ((theHour == 12) && (theMin == "00")) {
      aORp = "PM";
      } else if (hr >= 12) {
      aORp = "PM";
      } else {
      aORp = "AM";
      }
      timeSlots[theHour] = theHour +":"+ theMin +" "+ aORp;

      trace(theHour +":"+ theMin +" "+ aORp);//THIS IS WHAT I WANT IN THE DG COL
      }

      }
      }
      [Bindable]
      public var initDG:ArrayCollection;
      public function initData():void {
      initDG=new ArrayCollection(timeSlots);
      }

      ]]>
      </mx:Script>
      <mx:DataGrid x="10" y="10" id="timeGrid" dataProvider="{initDG}">
      <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="theHour"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>

      I get the following error as it is: 1120 Access of undefines property timeSlots

      Anyone?

      Thanks.
      -CK