Quantcast
Channel: Adobe Community : Popular Discussions - Archived Discussions
Viewing all articles
Browse latest Browse all 21156

Downloading multiple files, only one "finishes".

$
0
0

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; p

And 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();                }      }

Viewing all articles
Browse latest Browse all 21156

Trending Articles