As you know LoadVars receives a string in the form
id0=0&name0=joe&age0=16&id1=1&name1=patrick&age1=18&
You cannot loop over these 'records' because they are not 'identified' as such
by the LoadVars class. They are just a bunch of variables. So, you have to
build an array in Flash of the incoming data and then you can loop over the
elements in the array. Either you split the results in elements or you loop
over all the vars in the returned string to build the array.
1. Split the results
The string you return to Flash could be like this:
&results=0,joe,16,1,patrick,18
In Flash you build the array:
// array to hold the content
var content_array:Array=new Array();
// new LoadVars object to receive data
dataReceiver = new LoadVars();
dataReceiver.onLoad = function() {
content_array = this.content.split(","); // build an array of the
results using , as a seperator
for(i=0;i<content_array.length;i++){ // loop over the elements in the
array
myText_txt.text+=content_array+newline;
}
};
// Load the data
dataReceiver.load("
http://www.yourdomain.com/yourfile.asp");
2. Loop over the vars in the returned string:
You're returned string could look like this:
id0=0&name0=joe&age0=16&id1=1&name1=patrick&age1=18&
Loop over the vars and build the array:
// array to hold the content
var content_array:Array=new Array();
// new LoadVars object to receive data
dataReceiver = new LoadVars();
dataReceiver.onLoad = function(){
// clean all previous text
myText_txt.text="";
for(var prop in this){
if(prop != "onLoad"){
content_array.unshift(this[prop]);
//trace(content_array);
}
}
trace(content_array.length);
for(var i=0;i<content_array.length;i++){
myText_txt.text+=content_array+newline;
}
};
// Load the data
dataReceiver.load("
http://www.yourdomain.com/yourfile.asp");
To get all the results from the database you use
myData.load("GetData.asp",this) and have your ASP-file return a string with all
the results from the database.