# XML Random

**URL:** https://forum.kirupa.com/t/xml-random/116673
**Category:** Uncategorized
**Created:** [July 20, 2004, 2:47pm UTC](https://forum.kirupa.com/t/xml-random/116673 "2004-07-20T14:47:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rlLife](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@rlLife](https://forum.kirupa.com/u/rlLife)
#### Post date: [July 20, 2004, 2:47pm UTC](https://forum.kirupa.com/t/xml-random/116673/1 "2004-07-20T14:47:16Z")

</div>

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

```auto
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:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 20, 2004, 3:14pm UTC](https://forum.kirupa.com/t/xml-random/116673/2 "2004-07-20T15:14:23Z")

</div>

> [@rlLife](#):
>
> I know how to pull a random swf with actionscript. by doing this:
> 
> ```auto
> 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 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 20, 2004, 3:21pm UTC](https://forum.kirupa.com/t/xml-random/116673/3 "2004-07-20T15:21:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 20, 2004, 7:20pm UTC](https://forum.kirupa.com/t/xml-random/116673/4 "2004-07-20T19:20:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 20, 2004, 7:35pm UTC](https://forum.kirupa.com/t/xml-random/116673/5 "2004-07-20T19:35:57Z")

</div>

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
