Flex 下载文件 FileReference
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
? <mx:Script>?
?? <![CDATA[
?????????????
????private function ExportBinary():void {
?????? var FILE_URL:String = "/aa/data.txt";???// aa是工程名,data.txt是要下载的文件,放在工程目录下
?????? //var FILE_URL:String = "/aa/data.txt?rtp=" + String(Math.random() * 65535);?? rtp没有意义加上这么随机数是为了在下载文件时不去管客户端的缓存问题,服务器文件内容改变了可以下载到最新的文件。
???????var urlRequest:URLRequest = new URLRequest(FILE_URL);
???? ?var fileRef:FileReference = new FileReference();
??? ?fileRef.download(urlRequest);
?
}
?? ]]>?
? </mx:Script>?
???? <mx:VBox width="100%" height="100%">?
???????? <mx:Form>?
???????????? <mx:FormItem label="Export Datagrid items to Excel?" fontWeight="bold">?
???????????????? <mx:Form>?
???????????????????? <mx:HBox width="100%" verticalAlign="middle">??
??????????????????????????????????? <mx:Button label="binary" click="ExportBinary()"/>
???????????????????? </mx:HBox>?
???????????????? </mx:Form>?
???????????? </mx:FormItem>?
???????? </mx:Form>?
???? </mx:VBox>
</mx:Application>
?
?