Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: loop

  1. #1
    New Coder
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    loop

    All
    What's the most elegant solution for this horror.
    Should I loop through the array photos[]?
    Or should I loop the file names?
    Is there a sexy way of simplifying it?

    Code:
    photos[0]= new Image();
    photos[1]= new Image();
    photos[2]= new Image();
    photos[3]= new Image();
    photos[0].src="photos/Army Kev/army kev 1.jpg"
    photos[1].src="photos/Army Kev/army kev 2.jpg"
    photos[2].src="photos/Army Kev/army kev 3.jpg"
    photos[3].src="photos/Army Kev/army kev 4 (2001 birthday).jpg"
    photos[0].name="photos/Army Kev/army kev 1.jpg"
    photos[1].name="photos/Army Kev/army kev 2.jpg"
    photos[2].name="photos/Army Kev/army kev 3.jpg"
    photos[3].name="photos/Army Kev/army kev 4 (2001 birthday).jpg"
    Thanks

    Dan

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Something like
    Code:
    var photos= new Array();
    for(var i=0;i<=3;i++){
    photos[i]=new Image();
    	if(i==3){
    	photos[i].name=photos[i].src="photos/Army Kev/army kev "+(i+1)+" (2001 birthday).jpg"
    	}
    	else{
    	photos[i].name=photos[i].src="photos/Army Kev/army kev "+i+".jpg"
    	}
    	
    }
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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