0 Replies Latest reply on Jun 9, 2008 8:28 PM by Liceven

    Properties in CollectionEvent.items

      I am reading a flex tutorial here: Flex, PHP, JSON, MySQL - Advanced Updating. And iI met a problem.
      Here is the funcation get json data from java bean using remoteobject. and there is a listenter for CollectionEvent.COLLECTION_CHANGE event.:


      private function getJsonData(event:ResultEvent):void{
      var rawArray:Array;
      var arraySize:int;
      var rawData:String = event.result as String;
      rawArray = JSON.decode(rawData) as Array;
      dataArray = new ArrayCollection(rawArray);
      arraySize = dataArray.length;
      lblStatus.text="There are "+arraySize+"messages";

      dataArray is used as data provider for the datagrid control. We allow the user do something update in this control, and then put the modification back into the database. And then the dataChanged()funcation:

      private function dataChanged(event:CollectionEvent):void{
      var item:Object;
      var updatedObj:Object;
      var i:int;
      if(event.kind == CollectionEventKind.UPDATE){
      for(i=0;i < event.items.length;i++){
      item = event.items ;
      updatedObj = new Object;
      updatedObj.operation = "update"
      //updatedObj.id = item.source.id;
      //updatedObj.property = item.property;
      //updatedObj.value = item.source[item.property];

      }else if(event.kind == CollectionEventKind.REMOVE){
      for(i=0;i< event.items.length;i++){
      item = event.items
      updatedObj = new Object;
      updatedObj.operation = "delete";
      //updatedObj.id = item.id;

      pay attention to the properties like item.id, item.source.id ,item.property. But these properties don't exsit in flex3 lib. I got error message:TypeError: Error #1009: Cannot access a property or method of a null object reference.
      What is going on with thes properties? And how can i get the data changed by the user, then push it back into database?
      Thanks very much