1 Reply Latest reply on Nov 18, 2009 2:19 PM by Flex harUI

    CollectionEventKind.UPDATE

    sig_UVA

      Hi all,

       

      I have an array collection bound to a datagrid.  Adding and deleting records to the array collection works well.  However, the update has issues.  Clicking a record in the datagrid populates three text fields.  I change or or more of the values and then click the Update button.  The changes are reflected in the datagrid, but the CollectionEvent doesn't seem to handle the object correctly.

       

      The event.items Array shows the kind as update, but the newValue, oldValue, and property properties are null.  The source, which is an ObjectProxy looks fine.  I have tried this by making the selectedItem an Object versus an ObjectProxy.

       

      I do get the warnings:

      warning: unable to bind to property 'rating' on class 'Object' (class is not an IEventDispatcher)
      warning: unable to bind to property 'author' on class 'Object' (class is not an IEventDispatcher)
      warning: unable to bind to property 'name' on class 'Object' (class is not an IEventDispatcher)

       

      But a Google search really didn't clear it up for me; plus I don't get those warnings when adding or removing items.  I am also able to update the database by making the datagrid editable and editing the values in the grid directly.

       

      I appreciate your help.  Thanks!

       

      -Hunter

       

      code below

       

      private function arrayEditRecord(event:MouseEvent):void
                  {
                     
                      var selectedItem:ObjectProxy = new ObjectProxy(dgData.selectedItem);
                      selectedItem.name = txtTitle.text;
                      selectedItem.author = txtAuthor.text;
                      selectedItem.rating = txtRating.text;
                     
                      dataArray.itemUpdated(selectedItem);
                  }

       

       

      private function arrayAddRecord(event:MouseEvent):void
                  {
                      dataArray.addItem({name:txtTitle.text, author:txtAuthor.text, rating:txtRating.text});
                      clearInputs();
                  }

       

       

      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[i];
                              updatedObj = new Object;
                              updatedObj.id = item.source.id;
                              updatedObj.property = item.property;
                              updatedObj.value = item.source[item.property];
                              dataToUpdate.push(updatedObj);
                          }
                      }
                      else if(event.kind == CollectionEventKind.REMOVE)
                      {
                          for(i = 0; i < event.items.length; i++)
                          {
                              item = event.items[i];
                              updatedObj = new Object;
                              updatedObj.deleted = item.id
                              dataToUpdate.push(updatedObj);
                          }
                      }
                      else if(event.kind == CollectionEventKind.ADD)
                      {
                          for(i = 0; i < event.items.length; i++)
                          {
                              item = event.items[i];
                              updatedObj = new Object;
                              updatedObj.add = "1";
                              updatedObj.name = event.items[i].name;
                              updatedObj.author = event.items[i].author;
                              updatedObj.rating = event.items[i].rating;
                              dataToUpdate.push(updatedObj);
                          }
                      }
                     
                     
                      if(chkAutoUpdate.selected)
                      {
                          sendPHPData();
                      }
                  }