PDA

View Full Version : Can't loop properly through LoadVars object:HELP


sineadhartley
05-30-2005, 04:41 PM
Hi there
I have just completed tutorial called "loading dynamic data into flash" and now am trying to adapt it for my own use. Just one little small problem that i can't figure out in the for loop. My PHP script works fine coz i tested it in browser and a variable called "$cant" sends back to flash the total number of rows to process which is 3. Right so, below you can see that I assign the PHP variable "cant" to the flash variable "count" (var count = this.cant) and then i trace this to the output panel and i get "count = 3"...lovely..all going well...BUT when i use this variable "count" in the for loop, flash does not enter the loop and none of the load vars object is processed! But when I use the absolute number 3 in the loop i.e. for (var i = 0; i < 3; i++) everything works perfectly!!!! I think am going made because it just makes NOOOOO sense to me. Var count holds the value 3 so why will that variable not work in the for loop????? Can anyone at all help me out??

myData = new LoadVars();

//Fetch data
myData.onLoad = function(succes) {
if (succes) {
var count = this.cant;
trace("count = "+ count);
for (var i = 0; i < count; i++) {
trace("in for loop");
_root["Date_txt"+i].text = this["Date"+i];
_root["Course_txt"+i].text = this["Course"+i];
_root["College_txt"+i].text = this["College"+i];
_root["Grade_txt"+i].text = this["Grade"+i];
_root["Comments_txt"+i].text = this["Comments"+i];

}
} else {
trace("Error loading data");
}
};
stop();

Flash Gordon
05-30-2005, 04:45 PM
try adding this

var count = this.cant;
count = Number(count);
trace("count = "+ count)

I dont know if that will do it or not.

sineadhartley
05-31-2005, 04:15 PM
Hi Flash Jordan
I tried what you said but still no luck. It won't go into the for loop when i put in (var i = 0; i < count; i++) eventhough I have put a trace before the for loop and see that count = 3. It only way it goes into the for loop is when i put something like this (var i = 0; i < 3; i++). It juist doesn't make any sense!!! WEIRD

Flash Gordon
05-31-2005, 04:24 PM
count is mis-matched. It is not a number somehow. or not a length in an array like you think it is.