mike chambers | about

Looping Through DataProviders in ActionScript

I have received a couple of emails over the past couple of days, asking how to manually loop through a RecordSet / DataProviderClass. It is actually pretty simple and utilizes the getItemAt() and getLength() methods of the DataProviderClass (pseudo interface).

Here is the code:

//rs is a RecordSet object retrieved via FlashRemoting

var len = rs.getLength();
var tmpObj;

for(var i = 0; i < len; i++)
{
	tmpObj = rs.getItemAt(i);
	trace("Field 1 : " + tmpObj.field1);
	trace("Field 2 : " + tmpObj.field2);
}

This will work for all RecordSet and DataProviderClass classes.

Tags:
twitter github flickr behance