Skip navigation
Currently Being Moderated

CollectionEvent.COLLECTION_CHANGE stops firing

Aug 1, 2012 7:17 AM

Tags: #arraycollection #collectionevent

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?

 
Replies
  • Currently Being Moderated
    Aug 1, 2012 8:53 AM   in reply to iamcootis

    If you re-assign currentGroupInformation, you also have to re-add the event listener.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 12:07 PM   in reply to iamcootis

    I don’t know from your snippet, but it is the most likely reason.  It is less common to start with an empty collection and fill it than to replace collections from network data fetches.  But if it doesn’t pertain to you, there could be some other reason.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points