# HELP - Preloading a random background

**URL:** https://forum.kirupa.com/t/help-preloading-a-random-background/115985
**Category:** Uncategorized
**Created:** [July 13, 2004, 5:50pm UTC](https://forum.kirupa.com/t/help-preloading-a-random-background/115985 "2004-07-13T17:50:06Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![juicestain](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@juicestain](https://forum.kirupa.com/u/juicestain)
#### Post date: [July 13, 2004, 5:50pm UTC](https://forum.kirupa.com/t/help-preloading-a-random-background/115985/1 "2004-07-13T17:50:06Z")

</div>

Does anyone know how I can add code to preload a random background?

This is my current random background code-

choice = Math.round(Math.random()\*6);  
switch (choice) {  
case 0 :  
location.loadMovie(“bg0.swf”);  
break;  
case 1 :  
location.loadMovie(“bg1.swf”);  
break;  
case 2 :  
location.loadMovie(“bg2.swf”);  
break;  
case 3 :  
location.loadMovie(“bg3.swf”);  
break;  
case 4 :  
location.loadMovie(“bg4.swf”);  
break;  
case 5 :  
location.loadMovie(“bg5.swf”);  
break;  
case 6 :  
location.loadMovie(“bg6.swf”);  
break;  
}

and this is my preloader code-

bytes\_loaded = Math.round(\_root.getBytesLoaded());  
bytes\_total = Math.round(\_root.getBytesTotal());  
getPercent = bytes\_loaded/bytes\_total;  
\_root.loadBar.\_width = getPercent_100;  
\_root.loadText = Math.round(getPercent_100)+"%";  
if (bytes\_loaded == bytes\_total) {  
\_root.gotoAndPlay(3);  
}

Both were taken from tutorials on Kirupa, but I can’t figure out how to integrate them together. Thanks!

Justin
