AS3单击按钮后开始下载的功能!

Jen*_*erg 4 file download button actionscript-3

我的网站需要一个actionscript 3功能,让人们在点击按钮后下载文档.

无法在网上找到这个.

谢谢!詹妮弗

Ama*_*osh 5

一个FileReference ::下载()

btn.addEventListener(MouseEvent.CLICK, promptDownload);

private function promptDownload(e:MouseEvent):void
{
  req = new URLRequest("http://example.com/remotefile.doc");
  file = new FileReference();
  file.addEventListener(Event.COMPLETE, completeHandler);
  file.addEventListener(Event.CANCEL, cancelHandler);
  file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  file.download(req, "DefaultFileName.doc");
}

private function cancelHandler(event:Event):void 
{
  trace("user canceled the download");
}

private function completeHandler(event:Event):void 
{
  trace("download complete");
}

private function ioErrorHandler(event:IOErrorEvent):void 
{
  trace("ioError occurred");
}
Run Code Online (Sandbox Code Playgroud)