RecordSet.as filter() method fix for Flash MX 2004

I first encountered the issue with the RecordSet's filter() method around May of this year while working on a project with Flash MX. At the time, I documented it and mentioned the fix without actually posting any code on it.

In upgrading Opal to Flash MX 2004, I noticed that the issue remains in the latest RecordSet.as file in Flash MX 2004 and so, this time, I'm both documenting the bug and posting the code for the fix!

Here's the issue: The filter() method calls your custom filterFunction with *references* to each of the items in your RecordSet. Your filterFunction decides whether or not the current item should be included in the filtered RecordSet and returns the result to the RecordSet's filter() method. The filter() method then calls the addItem() method of the filtered RecordSet with the same reference to the original RecordSet item.

The problem is that the addItem() method (found in RsDataProviderClass.as) results in the ID of the original item being changed and this, of course, corrupts the original recordset.

The fix is simple. Instead of sending a reference to an original RecordSet item, we clone the original Recordset and send a copy of the original item. Thus, when the addItem() method alters the item's ID, it doesn't affect the item in the original RecordSet.

Because we still have no word on the Flash EULA issue I will refrain from posting any Macromedia code here. Instead, I will give you instructions for fixing your copy of RecordSet.as.

  1. Comment out (or delete) lines 298 - 301 in RecordSet.as
  2. In their place, enter this code.
That's it! Your filter() method should work perfectly now.

Comments