# How to load files and wait for completion with out executing other lines of code

**URL:** <https://forum.kirupa.com/t/how-to-load-files-and-wait-for-completion-with-out-executing-other-lines-of-code/309002>\
**Category:** flash\
**Created:** [May 4, 2010, 8:26pm UTC](https://forum.kirupa.com/t/how-to-load-files-and-wait-for-completion-with-out-executing-other-lines-of-code/309002 "2010-05-04T20:26:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardB](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@RichardB](https://forum.kirupa.com/u/RichardB)\
**Post date:** [May 4, 2010, 8:26pm UTC](https://forum.kirupa.com/t/how-to-load-files-and-wait-for-completion-with-out-executing-other-lines-of-code/309002/1 "2010-05-04T20:26:45Z")

</div>

Is there a way to load a file and waiting for the event listener with out continuing executing other code.

I tried using a while loop with a flag that is set by the on Complete in order to exit the wait loop.

This generates a timeout error.

private var loaded:Boolean = false;

function SpriteLoader(filepath:String){  
trace(“Attempting to Load File:” + filepath);  
FileLoader = new Loader();  
var FileRequest = new URLRequest(filepath);  
FileLoader.contentLoaderInfo.addEventListener(Event.OPEN, openedListener);  
FileLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);  
FileLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);

FileLoader.load(FileRequest);

wait();

}

//--------------------------------------------  
private function wait():void{

while(loaded == false){

}

}

//on complete  
//--------------------------------------------------  
private function completeListener(event:Event):void{  
trace(“SWF Loading complete”);  
loaded = true;  
}
