Copy link to clipboard
Copied
Hi,
I'm trying to make my code download multiples images without a dialog box for the user on the AIR app.
I've got an array containing 18 web links (like : "http://www.myWebsite.com/zootopia.jpg"). I'd like to download the 18 images and naming them image1, image2, image3...image18.
As my array is changing every week, the code needs to check if image1 already exists. If so, replace it.
Here's what I did so far :
var products:Array;
function saveImage (event:Event😞void {
var stream:URLStream = new URLStream();
var image1:File = File.documentsDirectory.resolvePath("image1.jpg");
var fileStream:FileStream = new FileStream();
stream.load(new URLRequest("http://www.myWebsite.com/lalaland.jpg"));
stream.addEventListener(Event.COMPLETE, writeComplete);
function writeComplete(evt:Event😞void {
var fileData:ByteArray = new ByteArray();
stream.readBytes(fileData,0,stream.bytesAvailable);
fileStream.openAsync(image1, FileMode.UPDATE);
fileStream.writeBytes(fileData,0,fileData.length);
fileStream.close();
trace("writeComplete");
trace(image1.url);
}
}
So my code is only downloading the specific link I gave him ("http://www.myWebsite.com/lalaland.jpg") and save it as "image1.jpg".
I'd like to download all the weblink of my "products" array.
How can I do ?
Also I'd like to name every files "image+number" (image1, image2).
Do you know how could I do that ?
Thank you for your help.