# AS3 Delay a for loop

**URL:** https://forum.kirupa.com/t/as3-delay-a-for-loop/304540
**Category:** flash
**Created:** [February 9, 2010, 4:56pm UTC](https://forum.kirupa.com/t/as3-delay-a-for-loop/304540 "2010-02-09T16:56:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![itbkris](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@itbkris](https://forum.kirupa.com/u/itbkris)
#### Post date: [February 9, 2010, 4:56pm UTC](https://forum.kirupa.com/t/as3-delay-a-for-loop/304540/1 "2010-02-09T16:56:20Z")

</div>

I’m writing an upload program to upload multiple files. It works great as long as I only upload one file but as soon as I add a second file it throws an error saying it can only perform one upload at a time. Is there a way I can have it not loop back through the for loop until the upload has completed?

Here is a chunk of my code

```auto

for(var q:int = 0; q < selectedFileArray.length; q++)
{
	trace("Loop marker 1");
	fr.addEventListener(Event.COMPLETE, completeHandler);
	fr.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ trace(e) }); 
	fr = FileReference(selectedFileArray[q]);
	fullfile = fr.name;
	filesplit = fullfile.split(".");
	fileext = filesplit[1];
	var uprequest:URLRequest = new URLRequest("www.myaddy.com");
	fr.upload(uprequest);
	function completeHandler(event:Event):void{ trace("Upload complete"); }
}

```
