Nested functions that return variables

Hi, I’ve got a little problem with a static function I’m writing.

I want it to return a MovieClip but only after a Loader has triggered its COMPLETE Event.

like so;


static public function loadBitmap(URL:String):MovieClip {
    
    // create MC
    // create Loader 
    // add EVENT_COMPLETE eventlistener to Loader
    // load supplied URL

    function onComplete(e:Event):void {        
        // add Loader to MC        
        // return MC here, but I can't because this function returns void
    }
    
}

which doesn’t work because the onComplete function returns void to nothing.

I could do it like this;


static public function loadBitmap(URL:String):MovieClip {
    
    // create MC    
    // create Loader 
    // add EVENT_COMPLETE eventlistener to Loader
    // load supplied URL
    
    // return MC here works fine, but not if there is an IOError during load
    
    function onComplete(e:Event):void {        
        // add Loader to MC        
    }
    
}

but it isn’t fool proof because the MC is returned before the Loader finishes loading.

Just wondering what the best practice would be.

Thanks.