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 :
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :

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:


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

lol Oks, good it worked :wink: