<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public var fileRe:FileReference=new FileReference()
private var file:FileReference;
private var currentAction:String;
private var downloadURL:URLRequest;
private function download():void{
var url:URLRequest=new URLRequest("http://localhost:8000/flex_fileupload/upload/handanda.txt");
file = new FileReference();
fileRe.addEventListener(Event.COMPLETE,comple)
fileRe.addEventListener(ProgressEvent.PROGRESS,jindu)
fileRe.download(url)
}
private function jindu(e:ProgressEvent):void{
var load:Number=e.bytesLoaded
var toal:Number=e.bytesTotal
var per:Number=Math.round(load/toal*100)
trace(per)
//tex.text=String(per)
}
private function comple(e:Event):void{
tex.text="已下载完成!"
}
]]>
</mx:Script>
<mx:Button x="10" y="20" label="下载一个文件" click="download()"/>
<mx:ProgressBar x="10" y="100" id="progress" source="fileRe" label="已加载: %3%%"/>
<mx:Text text="" x="10" y="105" id="tex"/>
</mx:Application>