# Loading random fullscreen background image

**URL:** <https://forum.kirupa.com/t/loading-random-fullscreen-background-image/258204>\
**Category:** Uncategorized\
**Created:** [April 22, 2008, 2:04am UTC](https://forum.kirupa.com/t/loading-random-fullscreen-background-image/258204 "2008-04-22T02:04:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkench](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mkench](https://forum.kirupa.com/u/mkench)\
**Post date:** [April 22, 2008, 2:04am UTC](https://forum.kirupa.com/t/loading-random-fullscreen-background-image/258204/1 "2008-04-22T02:04:24Z")

</div>

so, i finally got the fullscreen / scaling background to work. AND i can add .swf’s and other mc’s over top of it without any problem. however, i want to be able to have the background image randomly generated. i know how to do that on its own, but i can’t get it to work with this script. any advice?

here’s my fullscreen / scaling bg script.

> Stage.scaleMode = “noScale”;  
> \_global.imgConstantWidth = bgImage.\_width;  
> \_global.imgConstantHeight = bgImage.\_height;

setImage = function(mc){

```
var originalWidth = 1280;
var originalHeight = 850;
var widthGutter = (Stage.width - originalWidth)/2;
var heightGutter = (Stage.height - originalHeight)/2;

mc._x = -widthGutter;
mc._y = -heightGutter;

if (mc._width &gt; Stage.width){
    mc._x -= (mc._width-Stage.width)/2;
}

if (mc._height &gt; Stage.height){
    mc._y -= (mc._height-Stage.height)/2;
}

```

}

resizeImage = function(mc){

```
var scaleByWidth;

if (Stage.width/Stage.height &gt; _global.imgConstantWidth/_global.imgConstantHeight){
    scaleByWidth = true;
}else{
    scaleByWidth = false;
}

if (scaleByWidth){
    mc._height = Stage.width * _global.imgConstantHeight / _global.imgConstantWidth;
    mc._width = Stage.width;
} else {
    mc._width = Stage.height * _global.imgConstantWidth / _global.imgConstantHeight;
    mc._height = Stage.height;
}

```

}

setImage(bgImage);  
resizeImage(bgImage);

sizeListener = new Object();  
sizeListener.onResize = function() {  
setImage(bgImage);  
resizeImage(bgImage);  
};

Stage.addListener(sizeListener);
