Problem with multidimensional array

Hey

I’ve got this code which copies the multidimensional array elements to an other array when the elements get loaded.
But something is wrong, I think I may have made a mistake with the syntax.

It works great with a onedimensional array but it doesn’t even run with more dimensions.

I added the alert messages in the code to make sure where the process is.

Here’s the link:
http://web.zone.ee/testcss/


imagepreload[i][0] = new Image(); 

The value of imagepreload[i] is undefined. Looks like you want the value to be an array.


imagepreload[i] = [];
imagepreload[i][0] = new Image(); 

Yes, that’s the case.

But it seems, that the function inside the for loop doesn’t get to run at all.

I figured the array of fadeimages wasn’t instantiated either on the second dimension, so I did the same what you suggested with the imagepreload array.
There is still no change.

I’ve got to the line of error in the code.

The problem is with array push method,
it seems that it doesn’t like or support multidimensionality,
fadeimages[i][0].push( this.src );

Anyone got experience with this kind of thing?

This code implies a 3rd dimension


fadeimages[i][0].push( this.src );

If you really do want 3 dimensions, and not two, then it’s the same deal as the 2 posts back - you gotta assign an array object before you can use it like an array.

You don’t get any automatic default values in a javascript array.

I’m looking at your code, and I really don’t see why you need any multidimensional arrays at all.

I got it working,
the thing with push is, is that it just adds the element to the last place.

I used


fadeimages.push([this.src,,,]);

But now you can see that, I’ve created a timer for the slideshow.
But after the images get loaded then the visual page resets and the fadeshow gets added to the leftmost corner of the window.

The fadeshow requires 2-dimensional arrays, or that’s what I’m told,
it didn’t work with only a one dimensional array.

Asked about it before
http://www.sitepoint.com/forums/showthread.php?p=4568453#post4568453

Ah ok.

The reason the screen goes blank is due to the way document.write() works(fade.js calls it).
If you call it before the document has finished loading, then stuff gets written to the current document. If you call it afterwards, it clears everything in the document, and then writes. So you end up with pretty much nothing.

You might be able to make a container like <div id=“foobar”> and then replace those document.write calls with document.getElementById(“foobar”).innerHTML = someHtml;