# XML to call a random image

**URL:** https://forum.kirupa.com/t/xml-to-call-a-random-image/259664
**Category:** web dev
**Created:** [May 7, 2008, 4:10pm UTC](https://forum.kirupa.com/t/xml-to-call-a-random-image/259664 "2008-05-07T16:10:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![peejay](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@peejay](https://forum.kirupa.com/u/peejay)
#### Post date: [May 7, 2008, 4:10pm UTC](https://forum.kirupa.com/t/xml-to-call-a-random-image/259664/1 "2008-05-07T16:10:22Z")

</div>

Hi, I have an XML flash gallery which uses

\<img\>photoGallery/img1.jpg\</img\>

to call an image.

Is there a way to use the \<img\>\</img\> tags and call a random image from a folder?

Thanks

---

<div class="post-metadata">

### Author: ![flashdaddy](https://avatars.discourse-cdn.com/v4/letter/f/e36b37/32.png) [@flashdaddy](https://forum.kirupa.com/u/flashdaddy)
#### Post date: [May 24, 2008, 3:30pm UTC](https://forum.kirupa.com/t/xml-to-call-a-random-image/259664/2 "2008-05-24T15:30:42Z")

</div>

[quote=fasterthanlight™;2323161]this isn’t an XML problem,

its how you are manipulating the XML from within flash,

you probably have a For loop which iterates through your XML to output the value into an array,

Just output whatever is in your array with a random function.

var someArray:array = [“value1”, “value2” …]  
var randomInt:number = random(someArray.length);

trace (someArray[randomInt]);[/quote]

Hello,

I’m trying to do the exact same thing here. I have a movie clip on my stage which holds multiple images. I’d like that movieclip to display random images from my XML file. I used the code above just to see what would happen and I receive the following error:

1180: Call to a possible undefined method random

I’m using the same code as above:

```auto
var someArray:Array = ["value1", "value2", "value3", "value4", "value5", "value6"]
var randomInt:Number = random(someArray.length);

trace (someArray[randomInt]);

```

Any ideas why that’s not working?

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [May 24, 2008, 3:39pm UTC](https://forum.kirupa.com/t/xml-to-call-a-random-image/259664/3 "2008-05-24T15:39:01Z")

</div>

He said that the code wasn’t copy-and-paste-able. This code has a similar effect.

```auto
Math.floor(Math.random() * someArray.length)

```

---

<div class="post-metadata">

### Author: ![tecktalk](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@tecktalk](https://forum.kirupa.com/u/tecktalk)
#### Post date: [May 24, 2008, 3:50pm UTC](https://forum.kirupa.com/t/xml-to-call-a-random-image/259664/4 "2008-05-24T15:50:06Z")

</div>

hey…

there is no XML codes by which you can bring random images…the use above told you the way is the right way to add random images in flash…
