2 Replies Latest reply on Feb 6, 2010 8:24 AM by FinFlex

    ArrayCollection Filtering from CFC

    blastbeat
      All,

      I was following Forta's method of filtering data which can be found here http://www.forta.com/blog/index.cfm/2006/7/13/Filtering-Data-In-Flex.

      The difference with what I am doing is that I am receiving my data from a CFC. I am receiving the following error at runtime:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at test/::initApp()

      Here's my code, any suggestions?


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="initApp()">

      <mx:Script>
      <![CDATA[
      import mx.controls.Button;
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;

      [Bindable] private var Employees:ArrayCollection;

      private function initApp():void{
      qryUsers.selectAll();
      Employees.filterFunction=processFilter;
      }

      private function myMethodResult(event:ResultEvent):void {
      Employees = event.result as ArrayCollection;
      }

      public function processFilter(item:Object):Boolean
      {

      var result:Boolean=false;
      if (!item.FirstName.length || item.FirstName.toUpperCase().indexOf(txtSearch.text.toUpperCase()) >= 0)
      result=true;

      return result;
      }
      ]]>
      </mx:Script>

      <mx:RemoteObject id="qryUsers" source="employees" destination="ColdFusion" fault="Alert.show(event.fault.message)">
      <mx:method name="selectAll" result="myMethodResult(event)" />
      </mx:RemoteObject>

      <mx:Panel x="10" y="0" width="100%" height="100%" layout="absolute" title="Employee List">
      <mx:Canvas label="Employee List" width="100%" height="536" x="0" y="0">

      <mx:DataGrid x="0" y="64" width="100%" height="246" id="employeeList" dataProvider="{Employees}">
      <mx:columns>
      <mx:DataGridColumn headerText="First Name" dataField="FirstName" />
      <mx:DataGridColumn headerText="Last Name" dataField="LastName"/>
      <mx:DataGridColumn headerText="E-Mail" dataField="EmailAddress"/>
      <mx:DataGridColumn headerText="Department" dataField="Department"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Button x="10" y="555" id="btnEdit" label="Edit" enabled="false"/>
      <mx:Button x="66" y="555" label="Add Employee"/>
      <mx:TextInput x="427" y="20" id="txtSearch" change="Employees.refresh()"/>
      <mx:Label x="372" y="22" text="Search:"/>

      </mx:Canvas>
      </mx:Panel>

      </mx:Application>