FLEX文件下载

文件下载没有文件上传那么麻烦,只需从服务器指定的目录获取即可。

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 backgroundColor="#ffffff">
 <mx:Style source="styles/styles.css" />
 <mx:HRule x="10" y="37" width="90%"/>
 <mx:Text x="10" y="10" text="Downloading a File" styleName="headerStyle" id="label1"/>
 <mx:Button x="10" y="75" label="Download HTML Component" click="{download()}"/>
 <mx:Script>
  <![CDATA[
      import flash.events.*;
      import flash.events.DataEvent;
   import mx.events.CloseEvent;
   import mx.controls.Alert;
   import flash.net.navigateToURL;
     
   public function download():void {
    var url:String = encodeURI("http://localhost:8080/php/UpAndDownLoad/php/upload/images/qqpic.jpg");//encodeURI用来处理有中文的文件路径
    var request:URLRequest = new URLRequest(url);
    var fileRef:FileReference = new FileReference();
    configureListeners(fileRef);
    fileRef.download(request);
    //navigateToURL(new URLRequest("http://localhost:8080/php/UpAndDownLoad/php/upload/images/qqpic.jpg"), "_blank");
   }
   private function configureListeners(dispatcher:IEventDispatcher):void {
       dispatcher.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
       dispatcher.addEventListener(Event.SELECT,selectHandler);
       dispatcher.addEventListener(Event.OPEN,openHandler);
       dispatcher.addEventListener(ProgressEvent.PROGRESS,progressHandler);
       dispatcher.addEventListener(Event.CANCEL,cancelHandler);
       dispatcher.addEventListener(Event.COMPLETE,completeHandler);
     }
     public function ioErrorHandler(event:Event):void{
      trace("io error occured ");
     }
     public function selectHandler(event:Event):void{
    trace("selectHandler");
     }
     public function openHandler(event:Event):void{
      trace("File opened");
     }
     public function progressHandler(event:ProgressEvent):void{
      trace("File download in progress (" + event.bytesLoaded + " of " + event.bytesTotal + ")");
     }
     public function cancelHandler(event:Event):void{
      trace("cancelHandler");
     }
     public function completeHandler(event:Event):void{
      trace("File downloaded");
     }
  ]]>
 </mx:Script>
</mx:Application>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值