Skip to main content
November 16, 2006
Answered

Using LoadVar in a for loop?

  • November 16, 2006
  • 3 replies
  • 268 views
I have a list of filenames in an array pointing to data files on my hard drive. I'm trying to use a for loop to sequentially extract each filename from the array and load the file into an new array for later use. I have an onLoad event handler checking whether each file has been loaded.

Result: It looks like the loop goes through all of the filenames but only the last index gets loaded and pushed on to the new array i.e. all indices of the new array contain the data from the last loaded file.

Here is my code---can someone clue me as to what's wrong?

This topic has been closed for replies.
Correct answer
Thanks, this works! (with a few minor modifications)

* var loadContents = function() { ....otherwise it wouldn't run when called.
* set pageCount to -1 ....so the first post increment will set it to '0' for the first array index.
* set condition for exiting the routine to:
if ((pageCount+1) == _global.moduleContents.length) { ....to correct for pageCount use as array index number so it will match the array length

3 replies

November 17, 2006
You're welcome !
Correct answer
November 17, 2006
Thanks, this works! (with a few minor modifications)

* var loadContents = function() { ....otherwise it wouldn't run when called.
* set pageCount to -1 ....so the first post increment will set it to '0' for the first array index.
* set condition for exiting the routine to:
if ((pageCount+1) == _global.moduleContents.length) { ....to correct for pageCount use as array index number so it will match the array length

November 17, 2006
you cant establish more than one connectioins at a time.
Look , your for loop makes so many connections continuesly , without knowing the status of the all the connections.
So, for this case, you can use recursive functions..