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.

12 Responses to Looping Through DataProviders in ActionScript

  1. mozHD says:

    Same as above but this way you can keep the column names dynamic:var len = rs.getLength();var tmpObj;for (var i = 0; i<len; i++) {tmpObj = rs.getItemAt(i);trace(“Field 1 : “+tmpObj[rs.getColumnNames()[0]]);trace(“Field 2 : “+tmpObj[rs.getColumnNames()[1]]);}

  2. Very useful, thanks

  3. I tested the code, very useful, thanks

  4. http://www.sportsemotions.com/ says:

    Tres buenas páginas para comprar tikets y entradas de conciertos, futbol, carreras etc…http://www.madrid-football-tickets.com/http://www.barcelona-football-tickets.com/http://www.sportsemotions.com/

  5. http://www.sportsemotions.com/ says:

    Tres buenas páginas para comprar tikets y entradas de conciertos, futbol, carreras etc…http://www.madrid-football-tickets.com/http://www.barcelona-football-tickets.com/http://www.sportsemotions.com/

  6. http://www.sportsemotions.com/ says:

    Tres buenas páginas para comprar tikets y entradas de conciertos, futbol, carreras etc…http://www.madrid-football-tickets.com/http://www.barcelona-football-tickets.com/http://www.sportsemotions.com/