javascript - Why is image onload not working -


i realize common question asked novice javascript programmers am. console.log(img) , console.log("before onload") execute correctly never see image loaded message.

assetmanager.loadimages = function(urls) {    var images = [];    var urlcount = urls.length;    (var i=0; i<urlcount; i++) {       var img = new image();       images.push(img);    }    var urlsloaded = 0;    (var i=0; i<urlcount; i++) {       (function(img) {          console.log(img);          console.log("before onload");          img.onload = function(e) {             console.log("image loaded!");             urlsloaded++;             if (urlsloaded >= urlcount) {                assetmanager.callback(images);             }          }       })(images[i]);                   images[i].src = urls[i];    } } 

try var img = document.createelement("img");

or

assetmanager.loadimages = function(urls) {     var images = new array();     var urlcount = urls.length;     var urlsloaded = 0;     var leimg;     (var i=0; i<urlcount; i++) {         leimg = document.createelement("img");         leimg.onload = function(e){             urlsloaded++;             if (urlsloaded >= urlcount) {                // assetmanager.callback(images); --> balls, still             }         }         leimg.src = urls[i];         _images.push(leimg);     }  } 

(not tested, , drunk)


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -