<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Button label="下载EXCEL" click="{downloadSourceCodeZip(this._data)}"/>
<mx:Script>
<![CDATA[
import com.nsn.wy.business.model.Singleton;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import flash.net.FileReference;
[Bindable]
private var _kqiValue:Number;
[Bindable]
private var _dataValue:String;
[Bindable]
private var _data:Object;
private function clickHandler(evt:MouseEvent):void{
}
override public function set data(value:Object):void{
_data = value;
}
// 要下载文件的URL
private const FILE_URL:String = Singleton.getInstance().downurl;
private var fileRef:FileReference;
private var urlReq:URLRequest;
[Bindable]
private var fineName:String;
private function init():void {
// 定义一个FileReference对象,并填加一系列事件监听
fileRef = new FileReference();
fileRef.addEventListener(Event.CANCEL, doEvent);
fileRef.addEventListener(Event.COMPLETE, doEventOK);
fileRef.addEventListener(Event.OPEN, doEvent);
fileRef.addEventListener(Event.SELECT, doEvent);
fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
fileRef.addEventListener(ProgressEvent.PROGRESS, doEvent);
fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
}
private function doEvent(evt:Event):void {
// 取得当前FileReference的引用
var fr:FileReference = evt.currentTarget as FileReference;
// Alert.show("下载"+fineName+"文件失败");
}
private function doEventOK(evt:Event):void {
// 取得当前FileReference的引用
var fr:FileReference = evt.currentTarget as FileReference;
Alert.show("下载"+fineName+"文件成功");
}
private function downloadSourceCodeZip(value:Object):void {
// 以FILE_URL指定的地址建立一个URLRequest
// Alert.show(FILE_URL+value.addres);
fineName=value.addres;
urlReq = new URLRequest(FILE_URL+value.addres);
// 开始下载
fileRef.download(urlReq);
}
private function showAlert(item:Object):void {
Alert.show(item.eventString, item.type);
}
]]>
</mx:Script>
</mx:HBox>