SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whats problem in this code ?

    Hello forums!!
    I am using this code for preloading images
    Code JavaScript:
    var images = new Array();
    var i = 0;
    images[0] = "img/image1.gif";
    :
    :
    images[4] = "img/image5.gif";
    //alert(images.length);
    // start preloading..
    for(i = 0; i < images.length; i++){
    var imageObj[i] = new Image();
    imageObj[i].src = images[i];
    }
    and following error occurs (in firebug)
    missing ; before statement
    [Break on this error] var imageObj[i] = new Image(); \n
    Any Idea where i went wrong ..
    thanks in advance to all of you
    Last edited by PHPycho; Jul 17, 2007 at 21:14.

  2. #2
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var images = new Array();
    images[0] = "img/image1.gif";
    // ect

    images[4] = "img/image5.gif";

    //alert(images.length);// start preloading..

    var preBuffer = new Array();

    for(i = 0; i < images.length; i++)
    {
    preBuffer[i] = new Image();
    preBuffer[i].src = images[i];
    }

    The problem was "variable scope". you need to put the "var preBuffer" OUTSIDE the "for loop"


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
  •