actionscript-3flash-cs5flashurlloader

Loading a swf into a particular layer


I'm loading multiple swfs into a container swf, how do I decide which is on top of the other? Currently I'm loading a swf like this:

var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("example.swf");

myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);
function progressListener (e:ProgressEvent):void{
if (e.bytesLoaded == 0){
    //Upload loading status to zero
}else{
    //Upload loading status
}
}

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, startListener);
function startListener (e:Event):void{
addChild(myLoader.content);
}

myLoader.load(url);

Solution

  • Currently the order in which they are drawn to the screen depends on which file completes loading first.

    You could either download the swf file you want in the foreground, after the other one is loaded:

    function startListener(e:Event):void
    {
        addChild(myLoader.content);
        myLoader.load("url_of_the_swf_in_front");
    }
    

    or you could change the z-index afterwards:

    stage.setChildIndex(foregroundSwf, stage.numChildren -1);