2 Replies Latest reply on Apr 22, 2010 5:35 AM by BluetoothMacEgan

    Problems with getItemAt method of ArrayColection

    BluetoothMacEgan

      Hi Guys,

      I am having trouble getting the getItemAt method of the ArrayCollection class to work

       

      in ActionScript even though it seems to work fine in MXML.

      Any help greatly appreciated.

       

      In the attached code lines 95->97 work fine whereas line 35 throws a "Cannot access a

      property or method of a null object reference." error.

       

      Best regards,

      Anthony

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

      creationComplete="sanData.send();dispalyData()" backgroundColor="#2888F8"

       

      themeColor="#009DFF" width="672" height="1170"

      xmlns:ns1="assets.*" xmlns:local="*">

       

       

       

       

      <mx:Script>

       

       

      <![CDATA[

      import mx.rpc.events.ResultEvent;

      import mx.controls.dataGridClasses.DataGridColumn;

      import mx.collections.ArrayCollection;

       

       

      [Bindable]

      private var bookings:ArrayCollection;

       

       

       

       

       

      private function sanDataHandler(event:ResultEvent):void

      {

      bookings=event.result.data.row;

      }

       

       

       

       

      private function dispalyData():void

      {

      var temp = bookings.getItemAt(4).week;

      ShowNextWeek.text = " " + temp;

       

      }

       

       

      private function faultHandler

       

      (event:mx.rpc.events.FaultEvent):void

      {

      var eventInfo:String="event target:

       

      "+event.target+"\n\n";

      eventInfo+="event type: "+event.type+"\n\n";

      mx.controls.Alert.show(eventInfo,"Event Information");

      }

       

              

       

      ]]>

      </mx:Script>

       

        

      <mx:HTTPService url="http://bogus.com/xml.php"

          id="sanData"

          showBusyCursor="true"

          result="sanDataHandler(event)"

          fault="faultHandler(event)"

          method="POST" />

       

       

      <mx:Canvas x="10" y="22.4" width="629.2" height="1137.6" themeColor="#FFFFFF"

       

      borderStyle="solid" backgroundColor="#FFFFFF" borderColor="#EBE141" cornerRadius="4"

       

      borderThickness="7">

       

      <mx:DataGrid id="dataGrid" dataProvider="{bookings}"

       

      sortableColumns="true" 

      x="10" y="135"  height="377" alternatingItemColors="[#F0DFDF, #FFFFFF]"

      borderStyle="outset" borderColor="#4DA5E3" fontSize="13"

       

      fontWeight="bold" width="595.2">

      <mx:columns>

          <mx:DataGridColumn dataField="week"

                  headerText="Week"

                  headerStyleName="centered"

                  width="50"

                  textAlign="center"/>

                 

         <mx:DataGridColumn dataField="day"

                  headerText="Day"

                  headerStyleName="centered"

                  width="40"

                  textAlign="center"/>       

         

          <mx:DataGridColumn dataField="dept_name"

                  headerText="Class"

                  headerStyleName="centered"

                  width="200"

                  textAlign="center"/>

                 

           <mx:DataGridColumn dataField="room_name"

                  headerText="Room"

                  headerStyleName="centered"

                  width="125"

                  textAlign="center"/>

       

      </mx:columns>

      </mx:DataGrid>

       

      <mx:Text id="ShowWeek" x="10" y="15"  width="576"

       

      text="{bookings.getItemAt(3).week}" />

      <mx:Text id="ShowNextWeek" x="10" y="35"  width="576" />  <!--

       

      text="{bookings.getItemAt(4).week}" /> -->

      <mx:Label x="10" y="55"   text="{sanData.lastResult.data.row[0].week}"

       

      />

      </mx:Canvas>

      </mx:Application>