Question

I have problem with preloading images.

for(y=0;slide_image.lenght;y++){
   for(x=0;slide_image[y].lenght;x++){
      var preload_image=new Image();
      preload_image.src=slide_image[y][x];}
}

When I do it only with preload_image.src=slide_image[x]; it works, but when i have these two it doesn't. Maybe it's JavaScript bug?

Here is slide_image array:

var slide_image = new Array();

slide_image = [
    ['1/1.png', '1/2.jpg', '1/3.jpg', '1/4.jpg', '1/5.png'],
    ['2/text_1.png', '2/1.jpg', '2/2.jpg', '2/3.jpg', '2/4.jpg', '2/5.jpg', '2/6.jpg', '2/7.jpg'],
    ['3/1.jpg', '3/2.jpg', '3/3.jpg', '3/4.jpg', '3/5.jpg', '3/6.jpg']
];

Firebug and Firefox debugger says nothing. I don't know why this won't work.

Was it helpful?

Solution

You typo'd length and you are using for loops incorrectly. The middle "argument" to the loop should be a conditional expression which will determine when your loop stops.

Rewriting length and looping until your loop counters are less than the array's length, you get:


for (y = 0; y < slide_image.length; y++) {
    for (x = 0; x < slide_image[y].length; x++) {
        var preload_image = new Image();
        preload_image.src = slide_image[y][x];
    }
}

OTHER TIPS

for starters youve mistyped Length

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top