SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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/

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    imagepreload[i][0] = new Image();
    The value of imagepreload[i] is undefined. Looks like you want the value to be an array.
    Code:
    imagepreload[i] = [];
    imagepreload[i][0] = new Image();

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code implies a 3rd dimension
    Code:
    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.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working,
    the thing with push is, is that it just adds the element to the last place.

    I used
    Code:
    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/show...53#post4568453

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •