Depth Management problem

Hi to you all.

This is my first coding AS3 project and I’m stuck already.

I’ve build a theater with curtains and all.
After a button click I would like to load in a new “theater wall” swf, on top of the previous. And the next button will do the same.

The theater wall slides in so can’t be replaced by the previous one, it must be loaded into the next level. But at all times the curtain (“gordijn.swf”) must be on top of it all.

The way I’ve coded it, it will only works like this once. But when you push the button a second time the wall will load underneath the previous one…

I was experimenting with numChildren-1 but just can’t get it to work.

Some help will be appreciated

var imageRequest:URLRequest = new URLRequest("gordijn.swf");

var imageLoader:Loader = new Loader();

stage.addChildAt(imageLoader, 1);


var imageRequest2:URLRequest = new URLRequest("blauw.swf");

var imageLoader2:Loader = new Loader();

blauw.addEventListener(MouseEvent.CLICK, loader2);

function loader2(event:MouseEvent){
stage.addChildAt(imageLoader2, 1);


var imageRequest3:URLRequest = new URLRequest("groen.swf");

var imageLoader3:Loader = new Loader();

groen.addEventListener(MouseEvent.CLICK, loader3);

function loader3(event:MouseEvent){
stage.addChildAt(imageLoader3, 2);


var imageRequest4:URLRequest = new URLRequest("rood.swf");

var imageLoader4:Loader = new Loader();

rood.addEventListener(MouseEvent.CLICK, loader4);

function loader4(event:MouseEvent){
stage.addChildAt(imageLoader4, 3);