Load the first using Asset.image and in the onComplete event for that image load the next.
This function is a handy wrapper for it:
- function loadImagesConsecutively(srcs, complete, error){
- var imgs = [];
- function loadImage(i){
- if("undefined" !== typeof(srcs[i])){
- imgs[i] = new Asset.image(srcs[i], {
- onload: function(){
- loadImage(i + 1);
- },
- onerror: function(){
- if("function" === $type(error)){
- error(i, imgs[i], imgs);
- }
- }
- });
- } else{
- complete(imgs);
- }
- }
- loadImage(0);
- }
The function takes an array of image sources, a function to execute when the images are all loaded, and a function to execute if there is an error loading (so you don't wait forever for broken things to arrive)
You can use it like this (example that works)
- loadImagesConsecutively(
- [
- "http://mootools.net/assets/images/gradient.png",
- "http://mootools.net/assets/images/mootools.png",
- "http://mootools.net/assets/images/gradient-bottom.png"
- ],
- console.log
- );
Here's an example using the error callback as well (I'm using console.error as the callback, but obviously you can use your own function!)
- loadImagesConsecutively(
- [
- "http://mootools.net/assets/images/gradient.png",
- "http://mootools.net/assets/images/mootools.png",
- "http://mootools.net/assets/images/gradient-bottom.pngWILLNOTWORK"
- ],
- console.log,
- console.error
- );