Somehow I am unable to fire the onerror event or get the code in the onerror to work. This code is an attempt to collect a sequence of images in an array. I am using onerror event in order to mark the end of sequence and thus terminate the loop.
//definition of Slide object
function Slide(inpImage, imgCaption) {
this.inpImage = inpImage;
this.imgCaption = imgCaption;
}
window.onload = function() {
var defaultImage = img_slide.src; //This is a default file
//basically getting the file path and name of next image in the sequence
var nextImage = f_nextFile(f_path(img_slide.src),f_serial(img_slide.src));
//An array object which stores Slide Objects
arr_slides.push(new Slide(img_slide,img_slide.src));
while (defaultImage != nextImage){ //code to populate arr_slides array
var imgObj = new Image();
imgObj.src = nextImage;
arr_slides.push(new Slide(imgObj,nextImage));
//get the next image in the sequence of images
nextImage = f_nextFile(f_path(nextImage),f_serial(nextImage));
testImage = function(nextImage,defaultImage){
var tester=new Image();
tester.onerror = function () {
nextImage = defaultImage;
};
tester.onload = function () {
//do nothing
};
var loadNext = function() {
tester.src=nextImage;
};
loadNext();
};
testImage(nextImage,defaultImage);
}
alert("The number of images in array : " + arr_slides.length);
};