You are looking for multimedia events that say you can use, for example. loadeddata .
I would like to dwell on some other points:
- Characters within the regexp character group do not require escaping.
- Why not use jQuery to create elements and bind an event handler?
I changed the code a bit:
$.each(assets, function() { var r = /\.([^.]+)$/, ext = r.exec(this), //get file type tmp = ext[1] === 'png' ? $("<img>") : $("<audio>"), eventName = ext[1] === 'png' ? 'load' : 'loadeddata'; tmp .on(eventName, function() { var i = assets.indexOf(this); assets.splice(i, 1); if (!assets.length){ console.log('all loaded'); app.build(); } }) .attr("src", this); // only set after adding the load callback // to avoid a possible race condition });
pimvdb
source share