How to remove the previous picture from the slideshow?

Hey everyone,

I’m developing this fullscreen slideshow with random pictures which will be the background of a client’s web-site. I have everything working, the preloader, the imaging loading and transitions. There’s one thing however that’s happening and I don’t know how to fix it. What’s happening - naturally - is that the previous image is still there, in the background, and I would like that to be removed, I would like to have the previous loader, or just the holder movieclip to get off stage, but I really don’t know how to add that to my code.

What I was thinking was something in the lines of a for loop. Something like creating the picture’s holder inside that for loop so each will be like, picHolder1, picHolder2, picHolder3…and so on. And with that, on completion of the preloader I would remove something like “picHolder - i”. But how do I do that?

Here’s my code so far - so if possible could anyone help me adding the code to have it remove the previous picture/holder?


import flash.utils.*;
import caurina.transitions.Tweener;

var transitionTime:Number = 2;

var myTimer:Timer = new Timer(3000); // Muda de imagem a X milesimos de segundo.
myTimer.addEventListener("timer", timedFunction);

var picHolder:MovieClip = new MovieClip(); 
addChildAt(picHolder, 0); 
picHolder.x = 0; 
picHolder.y = 0; 

var pBarHolder:MovieClip = new MovieClip(); 
addChild(pBarHolder); 
pBarHolder.x = 0;
pBarHolder.y = 0;
var pBarWidth = stage.stageWidth;

var preloadBar:Shape = new Shape;
preloadBar.graphics.beginFill(0xFFFFFF);
preloadBar.graphics.drawRect(0, 0, pBarWidth,5); 
preloadBar.graphics.endFill();
pBarHolder.addChild(preloadBar);

preloadBar.visible = true;

var picArray = new Array(1, 2, 3, 4, 5, 6);
var randomPic = picArray[Math.floor((Math.random()*picArray.length))];
var currentPic = randomPic;
    
var picLoader:Loader = new Loader();
var _url:String = "images/" + randomPic + ".JPG";
    
picLoader.load( new URLRequest( _url ) );

picLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, showProgress );
picLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, showPic );
    
function showProgress( e:ProgressEvent ):void {
    
    var p:Number = e.bytesLoaded / e.bytesTotal;
    preloadBar.scaleX = p;
    
}
    
function showPic( e:Event ):void {
    
    preloadBar.visible = false;
    picHolder.x = 0;
    picHolder.y = 0;
    picLoader.width = stage.stageWidth;
    picLoader.height = stage.stageHeight;
    picLoader.alpha = 0;
    picHolder.addChild(picLoader);
    
    Tweener.addTween( picLoader, { alpha:1, time:transitionTime } );
    
    myTimer.start();
        
}

function timedFunction(eventArgs:TimerEvent) {
    
        trace("Timer fired " + myTimer.currentCount + " times.");
        
        preloadBar.visible = true;
        
        var oldPic = currentPic; 
        var picArray = new Array(1, 2, 3, 4, 5, 6);
        var randomPic = picArray[Math.floor((Math.random()*picArray.length))];
        
        
        if (randomPic == currentPic) {
            
            if (randomPic == 6) {
                randomPic = randomPic - 1;
            } else {
                randomPic = randomPic + 1;
            }
            
        }
        
        currentPic = randomPic;
        
        trace(randomPic);
        
        var picLoader:Loader = new Loader();
        var _url:String = "images/" + randomPic + ".JPG";
        
        picLoader.load( new URLRequest( _url ) );
        
        picLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, showProgress );
        picLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, showPic );
        
        function showProgress( e:ProgressEvent ):void {
            
            myTimer.stop();
            var p:Number = e.bytesLoaded / e.bytesTotal;
            preloadBar.scaleX = p;
            
        }
        
        function showPic( e:Event ):void {
            
            preloadBar.visible = false;
            picLoader.x = 0;
            picLoader.y = 0;
            picLoader.width = stage.stageWidth;
            picLoader.height = stage.stageHeight;
            picLoader.alpha = 0;
            picHolder.addChild(picLoader);
            
            Tweener.addTween( picLoader, { alpha:1, time:transitionTime } );
            
            myTimer.start();
            
        }

}

stage.addEventListener( Event.RESIZE, on_resize );

function on_resize(e:Event):void {
    
    picLoader.width = stage.stageWidth;
    picLoader.height = stage.stageHeight;
    
    preloadBar.width = stage.stageWidth;
    
}

EDIT: Forgot to add that I have what I’ve got so far online at http://www.tiagocabaco.com/pp/ - If you resize the stage you’ll notice that the previous picture is there so it makes it look bad. And about that, any way to make the picture expand AS the user expands the browser?

Thanks so much in advance!