1

どういうわけか、onerrorイベントを発生させたり、onerrorのコードを機能させることができません。このコードは、配列内の一連の画像を収集する試みです。シーケンスの終わりをマークしてループを終了するために、onerrorイベントを使用しています。

    //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);
     };
4

0 に答える 0