No UserDeparture Events (Possible Fix)

Hi,

I noticed that I was not receiving any UserDeparture events when a user leaves a chat room. I traced the problem to the getOccupantNamed() function in the room.as file.

It appeared that the for each loop was never going through each occupant. I have NO IDEA why the for each didn’t work, but changing it to a basic loop like this solved the issue and my UserDeparture events are back. Perhaps there is some bug with using the for each on **this. **Here’s the code if you want to change the trunk (simple enough):

for (var i = 0; i < this.length; i++)

{

var occ:RoomOccupant = this.getItemAt(i);

if ( occ.displayName == inName )

{

return occ;

}

}

I experienced the same behaviour - it took a little digging, but I’ve worked out what’s going on with regard to this.

The first thing to understand is the Xiff Room class no longer extends the Flex ArrayCollection class. It now extends a custom Xiff ArrayCollection class, presumably this was done to decouple it from the Flex framework.

The next thing to understand is that the “for each in” operator only works on a dynamic object or an Array. This is basically the reason why that loop does not iterate over the Xiff ArrayCollection (it is not a dynamic object or an Array). Your patch worked because the only methods/properties you are using are length and getItemAt(), both of which are implemented by the Xiff ArrayCollection.

The thing that took me a while to work out is why that loop previously worked on a Flex ArrayCollection (which it did). As it turns out if you look up the Flex ArrayCollection heirarchy, you get to a ListCollectionView class. This class extends Proxy and implements the key methods required to emulate a dynamic object/array: getProperty(), setProperty(), hasProperty(), nextNameIndex(), nextName(), nextValue() and callProperty(). This effectively allows the “for each in” loop to treat it like a dynamic object/array, which is why it just works like magic.

For anybody with checkin rights, this is a defect. Either any code using the Xiff ArrayCollection needs to be changed not to use a “for each in” loop or the Xiff ArrayCollection needs to be modified to emulate a dynamic object/array (which would be nice)

Regards

Rob

Good catch Rob.

I’ll update ArrayCollection to implement those methods: XIFF-63.

Hey crickeys and Rob,

Can you check out the patch I’ve added to XIFF-63?

I think that should fix your issues.

  • Mark

Applied patch - problem solved.

Nice work

Rob

Nice Job!