...

View Full Version : loop



Danfoord
08-08-2008, 01:44 PM
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?


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

abduraooft
08-08-2008, 02:06 PM
Something like
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"
}

} ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum