I have a function that allows you to load a new image. I want that function to make a function that detects when that image is loaded, and store it in an array or object. I have another function that will go through the array or object, and check each to see if it's loaded.
My question is, how can I add each new function to the array, and have each one return whether the image it's set to check is loaded or not?
** edit **
I want to pass a name to the function that loads images, to load 'images/'+name+'.png'
and then pass the name to the array or object as the name of the key.
** In reply to Shawn31313: here is the basic for what I have:
var resources = {
// I have other stuff to load here
'newImg': function(name) {
if (name) {
var img = new Image();
img.src = 'images/' + name + '.png';
imgLoadingArray[name] = function () {
var loaded = false;
// detect image loading some how
}
}
},
'imgLoadingArray': {},
'loaded': function() {
var loaded = true;
for (each in game.resources.imgLoadingArray) {
if (each == 'false') {
loaded = false;
}
return loaded;
}
}
}