<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009 "
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
minWidth="1024" minHeight="768">
<s:Button id="downLoad" x="64" y="252" label="下载" click="downLoad_clickHandler(event)"/>
<fx:Script>
<![CDATA[
import mx.managers.CursorManager;
import mx.controls.Alert;
private var FileRF:FileReference;
private var Url:URLRequest=new URLRequest('http://localhost/NJCIT_WebSite/DownLoadFile/test.rar');
protected function downLoad_clickHandler(event:MouseEvent):void
{
CursorManager.setBusyCursor();
FileRF=new FileReference();
FileRF.addEventListener(Event.COMPLETE, DownloadComplete);
FileRF.addEventListener(IOErrorEvent.IO_ERROR, DownloadIOError);
FileRF.addEventListener(SecurityErrorEvent.SECURITY_ERROR, DownloadSecurityError);
FileRF.download(Url);
}
private function DownloadIOError(event:IOErrorEvent):void
{
CursorManager.removeBusyCursor();
Alert.show("下载发生错误!");
}
private function DownloadSecurityError(event:SecurityErrorEvent):void
{
CursorManager.removeBusyCursor();
Alert.show("下载发生错误!");
}
private function DownloadComplete(event:Event):void
{
CursorManager.removeBusyCursor();
Alert.show("下载完成!");
}
]]>
</fx:Script>
</s:Application>
以上是特定文件的下载,下面两句是文本的下载,很简单吧!
var Fr:FileReference=new FileReference();
Fr.save("内容","FileName.txt");