SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    arrays pictues and backgroundImage

    This routine is supposed to change a background with successive images from an array. It worked when I wrote it inline in an html file it worked but having lifted it out I get the error 'missing ) after formal parameters'. What am I doing wrong?



    var box ={
    init: function(){
    box.box = document.getElementById("box");
    var mycars = new Array()
    mycars[0] = 'url(1.png)'
    mycars[1] = 'url(2.png)'
    mycars[2] = 'url(3.png)'
    mycars[3] = 'url(4.png)'
    mycars[4] = 'url(5.png)'
    mycars[5] = 'url(6.png)'
    box.swap();
    },

    swap: function(box.box,mycars)
    {
    for (i=0;i<mycars.length;i++)
    {
    box.box.style.backgroundImage = mycars[i];
    alert("break");
    }
    }
    };
    Last edited by gleb; Sep 9, 2007 at 11:26.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    Well mycars shouldn't exist in function swap because you have only declared it locally.

    Code:
    	
    arrays pictues and backgroundImage
    This routine is supposed to change a background with successive images from an array. It worked when I wrote it inline in an html file it worked but having lifted it out I get the error 'missing ) after formal parameters'. What am I doing wrong?
    
    
    
    var box ={
    init: function(){
    box.box = document.getElementById("box");
    var mycars = new Array()
    mycars[0] = 'url(1.png)'
    mycars[1] = 'url(2.png)'
    mycars[2] = 'url(3.png)'
    mycars[3] = 'url(4.png)'
    mycars[4] = 'url(5.png)'
    mycars[5] = 'url(6.png)'
    box.swap(mycars);
    },
    
    swap: function(cars)
    {
    for (i=0;i<cars.length;i++)
    {
    box.box.style.backgroundImage = cars[i];
    alert("break");
    }
    }
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right about the variables but it still doesn't work. No background gets placed. Help!


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
  •