# Actionscript Background Events Problem

**URL:** <https://forum.kirupa.com/t/actionscript-background-events-problem/211473>\
**Category:** flash\
**Created:** [January 2, 2007, 3:02am UTC](https://forum.kirupa.com/t/actionscript-background-events-problem/211473 "2007-01-02T03:02:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradox715](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paradox715](https://forum.kirupa.com/u/paradox715)\
**Post date:** [January 2, 2007, 3:02am UTC](https://forum.kirupa.com/t/actionscript-background-events-problem/211473/1 "2007-01-02T03:02:24Z")

</div>

This may be an easy question, but I just cannot figure it out.

I was doing one of the tutorials for loading random background images, and I was trying to revise it a bit.

**Goal:** When the flash starts, a random background image is displayed. The source of the random image is a jpg file contained in an external directory. On an ongoing basis, a non-technical user could just update the files in the directory without changing anything in the flash.

**My Problem:** I’m having trouble getting the Loader to display a random image to start with. I’ve been trying to use “on(Load)” to call a function that would change the Loader contents, but it doesn’t seem to work.

Here is the code in a frame

```auto
 
// This function works well, and pushes to my bgLoader a background of test1.jpg,
// test2.jpg, or test3.jpg. 
 

function RandomBackground():Void { [INDENT]choice = Math.round(Math.random()*2+1);[/INDENT][INDENT]bgLoader.contentPath = "test" + choice + ".jpg"[/INDENT]}; 

```

And here is the code on a movie clip which I was hoping would trigger the loader to load a random image.

```auto
 
onClipEvent(load) {
RandomBackground()
 } 

```

The code all validates, but I just get a blank screen. I know it is a problem with my onClipEvent(load) because the following code, placed onto a button, does randomly cycle through the images…

```auto
on(press) {
 RandomBackground()
}

```
