# Nested functions that return variables

**URL:** <https://forum.kirupa.com/t/nested-functions-that-return-variables/306290>\
**Category:** flash\
**Created:** [March 12, 2010, 11:28am UTC](https://forum.kirupa.com/t/nested-functions-that-return-variables/306290 "2010-03-12T11:28:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huwman](https://avatars.discourse-cdn.com/v4/letter/h/d9b06d/32.png) [@Huwman](https://forum.kirupa.com/u/Huwman)\
**Post date:** [March 12, 2010, 11:28am UTC](https://forum.kirupa.com/t/nested-functions-that-return-variables/306290/1 "2010-03-12T11:28:10Z")

</div>

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;

```auto

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;

```auto

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.
