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

标签 actionscript-3 file button download

我的网站需要一个 actionscript 3 函数,它可以让人们在单击按钮后下载文档。

在网上的任何地方都找不到这个。

谢谢!
詹妮弗

最佳答案

FileReference::download()

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");
}

关于actionscript-3 - 单击按钮后开始下载的 AS3 功能!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2972207/

相关文章:

arrays - 将MovieClips从舞台添加到阵列并播放它们

apache-flex - Flex 中的值对象设计模式

c++ - 为什么在 fopen() 没有关闭之后调用 close()?

file - 如何打开 .nsi 文件?

ios - 外部SWF在iOS上播放速度非常慢

arrays - 使用最小间隔/分布填充随机数数组?

Linux 文件描述符 - 获取当前重定向标准输出文件?

android - 如何设置按钮不可见android

javascript - 使用“下一步”按钮生成并循环随机数数组

C#:更改按钮背景颜色无效