Forum Moderators: open
var photoArray = new Array(
// filename, Width, Height, Caption
new Array("01.jpg", "400", "300"),
new Array("02.jpg", "400", "300"),
new Array("03.jpg", "400", "300"),
new Array("04.jpg", "400", "300"),
new Array("05.jpg", "400", "300),
new Array("06.jpg", "400", "300"),
new Array("07.jpg", "400", "300"),
new Array("08.jpg", "400", "300")
);
var myimages = new Array();
for (var i = 0; i < photoArray.length; i+=1) {
// here I need to extract the width and height from the PhotoArray
//How do I do this:
//Something like photoArray[i]. ...? extraxt width height from photoArray with for loop
//myimages[i] = new Image( photoArray[i]?, photoArray[i]?);
How to do the correct code?
myimages[i] = new Image(width,height);
// here I need to extract the filename from the PhotoArray
//same issue - extract filename with for loop
/Something like photoArray[i]. ...?
myimages[i].src = photoDir + filename;
myimages[i].id = "cacheimage" + i;
myimages[myimages[i].id] = myimages[i];
}
var photoNum = photoArray.length;
var photoDir = "path/to/images/";
var photoArray = new Array(
// filename, Width, Height, Caption
new Array("01.jpg", "400", "300"),
new Array("02.jpg", "400", "300"),
new Array("03.jpg", "400", "300"),
new Array("04.jpg", "400", "300"),
new Array("05.jpg", "400", "300),
new Array("06.jpg", "400", "300"),
new Array("07.jpg", "400", "300"),
new Array("08.jpg", "400", "300")
);
var myimages = new Array();
for (var i = 0; i < photoArray.length; i+=1) {
// here I need to extract the width and height from the PhotoArray
//How do I do this:
//Something like photoArray[i]. ...? extraxt width height from photoArray with for loop
//myimages[i] = new Image( photoArray[i]?, photoArray[i]?);
//How to do the correct code?
myimages[i] = new Image(width,height);
// here I need to extract the filename from the PhotoArray
//same issue - extract filename with for loop
//Something like photoArray[i]. ...?
myimages[i].src = photoDir + filename;
myimages[i].id = "cacheimage" + i;
myimages[myimages[i].id] = myimages[i];
}
var photoArray = new Array(
// filename, Width, Height, Caption
new Array("01.jpg", "400", "300"),
new Array("02.jpg", "400", "300"),
new Array("03.jpg", "400", "300"),
new Array("04.jpg", "400", "300"),
new Array("05.jpg", "400", "300),
new Array("06.jpg", "400", "300"),
new Array("07.jpg", "400", "300"),
new Array("08.jpg", "400", "300")
);
var myimages = new Array();
for (var i = 0; i < photoArray.length; i++) {
myimages[i] = new Image();
myimages[i].src=photoDir+photoArray[i][0];
myimages[i].width=photoArray[i][1];
myimages[i].height=photoArray[i][2];
myimages[i].id = "cacheimage" + i;
}
BTW, specifying the images' W & H isn't actually necessary. Unless you need the information for some later purpose, just create image objects with no args:
blah = new Image()