Here is my attempt at the ability to test if all images are loaded:
for (var i = 0; i < imgCount; i ++) {
loadArr[i] = false
imgArr[i] = new Image()
imgArr[i].src='img'+i+'.png'
imgArr[i].onload = function() {
loadArr[i] = true //but wait! At the end of
//the loop, i is imgCount
//so this doesn't work.
}
}
The problem is that once the loop is done, the variable i
is imgCount
. That means all the other "loaded" flags never get set to true
when their images are loaded.
Is there some way to add a "loaded" property to an image, or is there some workaround to this problem?