Copy link to clipboard
Copied
hey there, how do I initiate the download function in ActionScript3.0.?
(Where a dialogue box will be opened to let my users download a file from my server)
import flash.net.URLRequest;
import flash.net.FileReference;
download_btn.addEventListener(MouseEvent.CLICK , downloadFunction);
function downloadFunction(event: MouseEvent):void {
var req:URLRequest = new URLRequest('http://www.yoursite.com/downloads/filename.zip');
new FileReference().download(req);
}
Copy link to clipboard
Copied
Use FileReference.download()
Copy link to clipboard
Copied
ok, I'm new to Flash. Where do insert the directory of the file itself?
Copy link to clipboard
Copied
new FileReference().download(new URLRequest("URL of your file"));
Please note this can only be done upon user interaction such as button click.
Copy link to clipboard
Copied
I tried it Kenneth, it still doesnt work.
Please elaborate in detail.
Kind Regards
Lelo
Copy link to clipboard
Copied
Can you show us your code (only the relevant bit)?
Copy link to clipboard
Copied
var download_btn;
Copy link to clipboard
Copied
var download_btn should throw an error.
I“m assuming you have an instance by the name "download_btn" on your stage?
If so the code seems valid, use a statement like
try {
navigateToURL(request);
}
catch (e:Error) {
// handle error here
}
inside the downloadfunction to catch a possible error.
Copy link to clipboard
Copied
import flash.net.URLRequest;
import flash.net.FileReference;
download_btn.addEventListener(MouseEvent.CLICK , downloadFunction);
function downloadFunction(event: MouseEvent):void {
var req:URLRequest = new URLRequest('http://www.yoursite.com/downloads/filename.zip');
new FileReference().download(req);
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now