# Loading Random Image

**URL:** <https://forum.kirupa.com/t/loading-random-image/29981>\
**Category:** flash\
**Created:** [September 2, 2003, 4:53pm UTC](https://forum.kirupa.com/t/loading-random-image/29981 "2003-09-02T16:53:45Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![fantim](https://avatars.discourse-cdn.com/v4/letter/f/cc9497/32.png) [@fantim](https://forum.kirupa.com/u/fantim)\
**Post date:** [September 2, 2003, 4:53pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/1 "2003-09-02T16:53:45Z")

</div>

I want to make a button that loads a random image in a new window. Is this possible?

---

<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:** [September 2, 2003, 4:54pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/2 "2003-09-02T16:54:42Z")

</div>

In a new browser window ?

---

<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:** [September 2, 2003, 4:55pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/3 "2003-09-02T16:55:18Z")

</div>

Yep

---

<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:** [September 2, 2003, 5:01pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/4 "2003-09-02T17:01:10Z")

</div>

I think someone already aked this before. I don’t know who and where though. I’m gonna look into it.

- Maybe this can help you: [http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17767](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17767). It’s not the one I was looking for, though you might find it useful.

\*\* Found this one: [http://www.kirupaforum.com/forums/showthread.php?s=&threadid=23363](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=23363) and [http://www.kirupaforum.com/forums/showthread.php?s=&threadid=18323](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=18323) this one.

^ Those should get you starting 😉

---

<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:** [September 2, 2003, 5:30pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/5 "2003-09-02T17:30:12Z")

</div>

I didn’t see Voetsjoeba’s edit and made one in Flash real quick…It’s the same thing in all the other posts just in Flash:

```auto

pics=["pic1","pic2","pic3","pic4","pic5"];
randpic = pics[random(pics.length)];
_root.container.loadMovie(randpic+".jpg");

```

Same thing…just too slow; but when I’m in office…look out!! 😛

---

<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:** [September 2, 2003, 5:50pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/6 "2003-09-02T17:50:23Z")

</div>

These are great, but what about getting them to load in a new window? ie. \_blank

---

<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:** [September 2, 2003, 5:53pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/7 "2003-09-02T17:53:53Z")

</div>

Freddy - He/She was talking about a browser window, not Flash 😉

---

<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:** [September 2, 2003, 6:09pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/8 "2003-09-02T18:09:27Z")

</div>

Voetsjoeba; I think he/she was talking a bout a flash button that would load jpgs in a new window =)

> 

want to make a button that loads a random image in a new window. Is this possible?

```auto

use getUrl("_blank","image"+imagenumber+".jpg")

```

imagenumber correspond to pics like image1.jpg,image2.jpg etc…

---

<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:** [September 2, 2003, 6:14pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/9 "2003-09-02T18:14:01Z")

</div>

Just place the code Kit posted (which I’ll post below for your convenience) in a new html page. The code will generate a random image in the html page. So just call the html from flash using [AS]getURL(“java\*\*script:window.open(‘randomimage.html’,’’,‘height=300,width=400’);”);[/AS] if you want it to be a pop-up and all the images have the same size (300x400). Or simply use the basic [AS]getURL(“randomimage.html”,"\_blank")[/AS]That will bring up a big window though.

Here’s Kit’s code:

```php

<head>
<script language="JavaScript">
function random_imglink(){
var myimages=new Array()
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
</script>
</head>

```

\*Forgot the random\_imglink() at the end, this is important so make sure you don’t have the old script from before this edit.

---

<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:** [September 2, 2003, 6:17pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/10 "2003-09-02T18:17:30Z")

</div>

> \*Originally posted by mlkdesign \*  
> \*\*Voetsjoeba; I think he/she was talking a bout a flash button that would load jpgs in a new window =)

```auto

use getUrl("_blank","image"+imagenumber+".jpg")

```

imagenumber correspond to pics like image1.jpg,image2.jpg etc… \*\*

I know. A browser window should open, it shouldn’t be loaded in the flash movie. The code Freddy posted would work fine to load them into Flash.

```auto

getUrl("_blank","image"+imagenumber+".jpg")

```

Correct me if I’m wrong, but that doesn’t seem right to me. I don’t know if you can even load images through getURL, but I don’t think so. Even if, it should be [AS]getURL(“image”+imagenumber+“.jpg”,“\_blank”);[/AS]don’t you think ? ([getURL info](http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary377.html))

\*\*\* Make sure you see my edit in the previous post\*\*

---

<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:** [September 2, 2003, 7:59pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/11 "2003-09-02T19:59:17Z")

</div>

Can you load a URL into flash?

---

<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:** [September 2, 2003, 9:08pm UTC](https://forum.kirupa.com/t/loading-random-image/29981/12 "2003-09-02T21:08:13Z")

</div>

> 

Freddy - He/She was talking about a browser window, not Flash

After a little reasearch, I was answering someone else’s question from another post (loading random images in my footer). Hmm, guess I was tired…😛

Voetsjoeba - not as clean by any means, but you can use getURL for other files like pics; I just tried it 'cause I wasn’t sure, but in my experience - it’s not good because it displays the pictures address in the title bar.

I’d go with what Voetsjoeba said a few posts ago - that’s gonna be your best way 😉

> Can you load a URL into flash?

You can’t load an HTML page into flash, but you can load in images, text, partially formatted HTML text.
