Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

download file from server

Guest
Feb 03, 2011 Feb 03, 2011

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)

TOPICS
ActionScript
975
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 08, 2011 Feb 08, 2011
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);
}
Translate
Community Expert ,
Feb 03, 2011 Feb 03, 2011

Use FileReference.download()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 03, 2011 Feb 03, 2011

ok, I'm new to Flash. Where do insert the directory of the file itself?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2011 Feb 03, 2011
new FileReference().download(new URLRequest("URL of your file"));

Please note this can only be done upon user interaction such as button click.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 08, 2011 Feb 08, 2011

I tried it Kenneth, it still doesnt work.

Please elaborate in detail.

Kind Regards

Lelo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2011 Feb 08, 2011

Can you show us your code (only the relevant bit)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 08, 2011 Feb 08, 2011

var download_btn;


download_btn.addEventListener(MouseEvent.CLICK , downloadFunction);
function downloadFunction(event: MouseEvent)
{
    var request:URLRequest = new URLRequest('http://www.yoursite.com/downloads/filename.zip');
    navigateToURL(request);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 08, 2011 Feb 08, 2011

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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2011 Feb 08, 2011
LATEST
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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines