XML Random

I know how to pull a random swf with actionscript. by doing this:

choice = Math.round(Math.random()*6);
switch (choice) {
case 0 :
	location.loadMovie("image0.swf");
	break;
case 1 :
	location.loadMovie("image1.swf");
	break;
case 2 :
	location.loadMovie("image2.swf");
	break;
case 3 :
	location.loadMovie("image3.swf");
	break;
case 4 :
	location.loadMovie("image4.swf");
	break;
case 5 :
	location.loadMovie("image5.swf");
	break;
}

But what i want to do is have an xml file that will load up a random jpg into a movie clip in flash. How hard is this to do? I dont want to have to use the solution listed above.

Also i know that i could do this with an array but i have like 150 jpgs so it would be a crazy lot of actionscript and i think that might slow down the movie

rL :ch:

That’s unlikely, as an XML doc with 150 childnodes takes up significantly more memory than a simple array with 150 elements :wink:

ok yeah i guess i didnt think of the fact that the whole xml doc would have to load as well. so you think i should just go for the array. is there any other way to do it without having to list all of the differnt jpgs in the array. i am only thinking this out because if the client wants to add more later then i dont have to mess with the flash file they could just drop the photos in.

I don’t really know but why don’t you try to name the jpegs 1 to 150 and make a random selection, no array and no switch. Just create an empty movie clip and load the jpg directly. I don’t know if I’m explaning myself.

Here’s the code:

movieClip.loadMovie(randomNumber+".jpg");

Hope this helps

that is what i ended up doing. i searched around and learned that this was possible. sorry i should have posted that i worked it out. thanks for your help