强制下载使用Flash AS3

编程入门 行业动态 更新时间:2024-10-20 01:19:41
本文介绍了强制下载使用Flash AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想有力量的下载功能只与Flash AS3,有没有可能?我试图谷歌,但失败了。这里是我的AS3 code ......

i want to have force download functionality only with Flash AS3, is it possible ?? i tried google but failed. here it is my as3 code......

var file_URLRequest:URLRequest = new URLRequest ("mp3gallery/" + url); var content_header:URLRequestHeader = new URLRequestHeader("Content-Type: application/force-download"); var attach_header:URLRequestHeader = new URLRequestHeader("Content-Disposition: attachment; filename=abc.mp3"); file_URLRequest.requestHeaders.push(content_header); file_URLRequest.requestHeaders.push(attach_header); file_URLRequest.method = URLRequestMethod.POST; navigateToURL(file_URLRequest, '_blank');

感谢你。

推荐答案

这是的直接从文档:

package { import flash.display.Sprite; import flash.events.*; import flash.FileReference; import flash.URLRequest; import flash.FileFilter; public class FileReference_download extends Sprite { private var downloadURL:URLRequest; private var fileName:String = "SomeFile.pdf"; private var file:FileReference; public function FileReference_download() { downloadURL = new URLRequest(); downloadURL.url = "www.[yourDomain]/SomeFile.pdf"; file = new FileReference(); configureListeners(file); file.download(downloadURL, fileName); } private function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.CANCEL, cancelHandler); dispatcher.addEventListener(Event.COMPLETE, completeHandler); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); dispatcher.addEventListener(Event.OPEN, openHandler); dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); dispatcher.addEventListener(Event.SELECT, selectHandler); } private function cancelHandler(event:Event):void { trace("cancelHandler: " + event); } private function completeHandler(event:Event):void { trace("completeHandler: " + event); } private function ioErrorHandler(event:IOErrorEvent):void { trace("ioErrorHandler: " + event); } private function openHandler(event:Event):void { trace("openHandler: " + event); } private function progressHandler(event:ProgressEvent):void { var file:FileReference = FileReference(event.target); trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal); } private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler: " + event); } private function selectHandler(event:Event):void { var file:FileReference = FileReference(event.target); trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url); } } }

编辑:如果用这样的方式,因为可能需要在用户(点击)的动作,这可能无法工作。所以,你应该将包含在构造函数的方法的code(Click处理程序)。当然,在这种情况下, BTN 是一个影片剪辑放置在舞台上的实例名,而 FileReference_download 是的DocumentClass。

this could not work if used this way, because an action of the user (a click) may be required. So you should move the code contained in the constructor to a method (click handler). Of course, in this case btn is the instance name of a movieclip placed on stage, while FileReference_download is the DocumentClass.

public function FileReference_download() { btn.addEventListener(MouseEvent.MOUSE_DOWN, downloadMyFile); } private function downloadMyFile(e:MouseEvent){ downloadURL = new URLRequest(); downloadURL.url = "www.[yourDomain]/SomeFile.pdf"; file = new FileReference(); configureListeners(file); file.download(downloadURL, fileName); }

更多推荐

强制下载使用Flash AS3

本文发布于:2023-11-23 16:00:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:下载使用   Flash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!