Posted on Monday 2 January 2006
Here's a bizarre little problem I ran into integrating Flash Media Server 2, Flash 8 and amfphp. mx.remoting.RecordSet has a getter/setter called 'items' which actually points to the _items member. Now if I forward a RecordSet from amfphp to FMS2 to the Flash player, I can read the RecordSet perfectly fine in FMS2, and I can see the RecordSet come back to Flash in the NetConnection debugger.
The trouble is that when I try use the RecordSet in Flash, it won't work. trace(this.items) traces an empty line. this.items.length is always undefined. But the crazy thing is that I see it in the NetConnection debugger, under this.items! wtf is going on, you ask?
Well, what I understand is that in fact FlashCom's RecordSet obejct is not the same as that sent by the trusty amfphp. When a RecordSet comes from amfphp, an instance of mx.remoting.RecordSet is created and _items is set to the value of the records array. When it comes back from FMS2, however, the RecordSet is instantiated but in that case there is already an 'items' array defined in the AMF packet. So the Flash player does its magic and at some point 'items' the member obscures 'items' the getter/setter.
Dig this:
trace(rs['items'] == rs.items); //traces false!!!
Apparently the NetConnection debugger picks up the object before it's wrapped in mx.remoting.RecordSet. Thereafter I can read the items only if I use bracket syntax. The solution which only took me 4 hours to find:
rs['_items'] = rs['items'];
Sigh... Another episode in my love/hate soap-opera relationship with FlashCom. Feels like Dallas... Stay tuned, Flex 2 shoots JR next...


