I'm working on an application that will download images from a remote website. When selecting one URL the code works great. When I loop over an array containing two or more URLs, only the last file in the array actually downloads. All other files show up in the file system as zero length JPGs. I'm not sure what might be happening, but I'm posting my code in hopes that someone sees something that I don't.
Here's the loop
for (var p=0; pAnd here's the contents of the downloadFile function.
function downloadFile(url, fileName) { var req = new air.URLRequest(url); stream = new air.URLStream(); stream.addEventListener(air.Event.COMPLETE, writeAirFile); stream.load(req); function writeAirFile(e) { //air.Introspector.Console.log(e); var fileData = new air.ByteArray(); stream.readBytes(fileData,0,stream.bytesAvailable); var fileStream = new air.FileStream(); fileStream.openAsync(fileName, air.FileMode.WRITE); fileStream.writeBytes(fileData,0); fileStream.close(); } }