3 Replies Latest reply: Aug 1, 2012 12:07 PM by Flex harUI RSS

    CollectionEvent.COLLECTION_CHANGE stops firing

    iamcootis Community Member

      I have an array collection.

       

      [Bindable]
      public var currentGroupInformation:ArrayCollection = new ArrayCollection();
      

       

      And it has this listener.

       

      currentGroupInformation.addEventListener(CollectionEvent.COLLECTION_CHANGE, currentGroupCollectionEventHandler);
      

       

       

      public function currentGroupCollectionEventHandler(event:CollectionEvent):void {
                  var debugXML:XML = <debug token="#FLASHTRACE">{event.kind}</debug>;
                  appModel.sendMessage(debugXML);
                  switch(event.kind) {
                      case CollectionEventKind.ADD:
                          var tempPort:Port = event.items[0] as Port;
                          trace("Item "+ tempPort.portID + " added");
                          trace("currentGroupInformation : "+currentGroupInformation.length);
                          break;
                      case CollectionEventKind.REMOVE:
                          trace("Item "+ event.location + " removed");
                          break;
                      case CollectionEventKind.REPLACE:
                          trace("Item "+ event.location + " Replaced");
                          break;
                      case CollectionEventKind.UPDATE:
                          trace("Item updated");
                          if( event.items[0].property == "portProcessState"){
                              if( event.items[0].newValue != "idle" ){
                                  this.isGroupBusy = true;
                              }else{
                                  isGroupBusy = false;
                              }
                              trace("portProcessState:: "+isGroupBusy);
                          }
                          break;
                      case CollectionEventKind.RESET:
                          trace("Item reset");
                          break;
                  }
              }
      

       

      Basically, I need to know when the arrayCollection is updated, so the isGroupBusy value will change.

      It seems to work fine the first couple of times, and then it stops working altogether. No idea what is going on.

       

      The only other function that gets called that manipulates currentGroupInformation is this:

       

      public function buildCurrentGroupInformationArray():void{
                  checkToSeeIfCurrentGroupReservationsHaveChanged();
                  if(hasCurrentGroupReservationChanged){
                      currentGroupInformation.removeAll();
                      
                      var portSort:SortField = new SortField("portID", false, false,true);
                      var slotSort:SortField = new SortField("slotID", true);
                      var sort:Sort = new Sort();
                      //sortField.descending = true;
                      sort.fields = [slotSort,portSort];
                      
                      currentGroupInformation.sort = sort;
                      
                      currentGroupInformation.refresh();
                      isGroupBusy = false;
                      for each (var theSlot:Slot in chassisSlot){
                          for each( var port:Port in theSlot.portArray){
                              if(port.isReserved){
                                  if( port.reservedBy.toLowerCase() == appModel.user.id.toLowerCase() ){
                                      if(port.portGroup == appModel.user.group){
                                          if( port.process != null ){
                                              if( !port.process.completed ){
                                                  this.isGroupBusy = true;
                                              }else{
                                                  isGroupBusy = false;
                                              }
                                          }else{
                                              isGroupBusy = false;
                                          }
                                          currentGroupInformation.addItem(port);
                                      }
                                  }
                              }
                          }
                      }
                      currentGroupInformation.refresh();
                  }
              }
      

       

      Is there a bug in the CollectionEvent or are we doing something to make it stop firing events?