Random Images

Trupaderos
Trupaderos used Ask the Experts™
on
How to write an array that randomizes 5 images, in a variable array. Such as "var intArr".

Note: cannot be written with document.write
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
supposingly u have 5 images in the same folder, named img1, img2, img3, img4 and img5

u might wana use a for loop and do it

Image[] imgArr = new Image[5];

for (int i=0; i<imgArr.length; i++) {
String
}
oops clicked wrongly

supposingly u have 5 images in the same folder, named img1, img2, img3, img4 and img5 in .jpg format

u might wana use a for loop and do it

Image[] imgArr = new Image[5];

for (int i=1; i<=imgArr.length; i++) {
String imageFile = "img" +i "+.jpg";
Image img = getImage (getDocumentBase(), imageFile);
imgArr[i-1] = img;
}

this way .. i guess an image array of size 5 with the 5 files are added into the array

:)
-=[sKySh@DoW]=-
If you want a little advanced script use this :

int imagesnumber;

//read imagesnumber;

Image[] imgArr = new Image[imagesnumber];

for (int i=1; i<=imgArr.length; i++) {
String imageFile = "img" +i "+.jpg";
Image img = getImage (getDocumentBase(), imageFile);
imgArr[i-1] = img;
}

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for skyshadow

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial