0

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.

1
  • Please see my edits for the reason why I say JSBeautifier.org is great for helping us to understand and fix your question :-) Commented Oct 29, 2011 at 15:34

2 Answers 2

2

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];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

for starters youve mistyped Length

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.