# HELP WITH \*Random Image Fading\*

**URL:** <https://forum.kirupa.com/t/help-with-random-image-fading/317010>\
**Category:** flash\
**Created:** [December 7, 2010, 10:34pm UTC](https://forum.kirupa.com/t/help-with-random-image-fading/317010 "2010-12-07T22:34:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeoffS](https://avatars.discourse-cdn.com/v4/letter/g/b9bd4f/32.png) [@GeoffS](https://forum.kirupa.com/u/GeoffS)\
**Post date:** [December 7, 2010, 10:34pm UTC](https://forum.kirupa.com/t/help-with-random-image-fading/317010/1 "2010-12-07T22:34:21Z")

</div>

I have a chunk of code in AS2 that calls a random image. I’ve been trying to figure out how to add a fade to it without any luck.

Here’s the code for the **RANDOM** background:

```auto

function randomBG(){
    function randRange0(min:Number, max:Number):Number {
        // Generate a number between and including 20-25
        var randomNum0:Number = Math.floor(Math.random()*(max-min+1))+min;
        return randomNum0;
    }

    // Get random number created
    var bg:Number = randRange0(20, 24);

    // Load image into holder on the stage. images should be numbered sequentially
    background_mc.loadMovie("images3-bg/"+bg+".jpg");    
    trace(bg);
}

setInterval(randomBG,35000); 

```

Here’s the code for the **FADE** on the background (that I’ve been trying to combine):

```auto

background_mc._alpha = 0; 

background_mc.onEnterFrame = function(){
    if(background_mc._alpha == 100){
        delete background_mc.onEnterFrame;
        } else {
            background_mc._alpha += 5;
        } 
}

```

I’ve been trying to combine the two chunks of code in different ways but it ends up loading the background with an alpha of 5 (I’ve tested this by changing the number to 90/100 and it loads with almost a full alpha).

How come it is not fading in no matter where/how I put in the code? Someone please help me with an example (or the solution)…
