1.当点击"导出到PDF"按钮时,会弹出一个下载对话框,并显示下载进度条。如下图
2.选择好保存路径和文件名后,点击保存。就开始下载。下载完成。进度条显示如下图
3.点击确定按钮。则进度条就会消失。
4.如果在弹出下载对话框时,你取消了下载。则进度条也跟随消失。
不过,整个应用有两个问题未解决。还请高手解决。
1.下载过程中,进度条没有发生动态变化。
2.第一次下载成功后,再次重新点击时,进度条背景颜色未能成功初始化。我用了this.progressBar.setStyle("trackColors","#0000FF") ;这句代码。但还是没有效果。从之前一系列组件的应用来看,感觉flex3对CSS支持不理想。
好了。奉献代码如下:
AS代码:
private var downloadURLRequest:URLRequest;
private var file:FileReference;
private function exportToPDF():void
{
var url:String = "/HouseRentMS/download?queryDate="+queryDate;
downloadURLRequest = new URLRequest(url);
file = new FileReference();
configureListeners(file);
var fileName:String ="房租明细("+this.queryDate+").pdf";
this.progressBar.visible = true;
file.download(downloadURLRequest,fileName);
}
private function configureListeners(dispatcher:IEventDispatcher):vo id {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS ,progressHandler);
dispatcher.addEventListener(Event.CANCEL,cancelHan dler);
}
private function progressHandler(event:ProgressEvent):void {
var fileUploadPercent:uint= event.bytesLoaded/event.bytesTotal*100;
progressBar.setProgress(fileUploadPercent, 100);
progressBar.label = "已完成" + fileUploadPercent + "%";
}
private function cancelHandler(event:Event):void
{
this.progressBar.visible = false;
}
private var btn:Class;
private function completeHandler(event:Event):void
{
Alert.okLabel="确定";
Alert.show("下载完成", "提示",
Alert.OK, this,closeHandlerEvent,btn,Alert.OK);
}
private function closeHandlerEvent(event:CloseEvent):void{
this.progressBar.label = "当前进度: 0%";
this.progressBar.visible = false;
//下面这句代码是初始化进度条背景颜色,但没有效果
//this.progressBar.setStyle("trackColors","#0000FF ");
}
private function ioErrorHandler(event:IOErrorEvent):void
{
Alert.show(event.toString(),"提示");
}
MXML代码:
2.选择好保存路径和文件名后,点击保存。就开始下载。下载完成。进度条显示如下图
3.点击确定按钮。则进度条就会消失。
4.如果在弹出下载对话框时,你取消了下载。则进度条也跟随消失。
不过,整个应用有两个问题未解决。还请高手解决。
1.下载过程中,进度条没有发生动态变化。
2.第一次下载成功后,再次重新点击时,进度条背景颜色未能成功初始化。我用了this.progressBar.setStyle("trackColors","#0000FF") ;这句代码。但还是没有效果。从之前一系列组件的应用来看,感觉flex3对CSS支持不理想。
好了。奉献代码如下:
AS代码:
private var downloadURLRequest:URLRequest;
private var file:FileReference;
private function exportToPDF():void
{
var url:String = "/HouseRentMS/download?queryDate="+queryDate;
downloadURLRequest = new URLRequest(url);
file = new FileReference();
configureListeners(file);
var fileName:String ="房租明细("+this.queryDate+").pdf";
this.progressBar.visible = true;
file.download(downloadURLRequest,fileName);
}
private function configureListeners(dispatcher:IEventDispatcher):vo id {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS ,progressHandler);
dispatcher.addEventListener(Event.CANCEL,cancelHan dler);
}
private function progressHandler(event:ProgressEvent):void {
var fileUploadPercent:uint= event.bytesLoaded/event.bytesTotal*100;
progressBar.setProgress(fileUploadPercent, 100);
progressBar.label = "已完成" + fileUploadPercent + "%";
}
private function cancelHandler(event:Event):void
{
this.progressBar.visible = false;
}
private var btn:Class;
private function completeHandler(event:Event):void
{
Alert.okLabel="确定";
Alert.show("下载完成", "提示",
Alert.OK, this,closeHandlerEvent,btn,Alert.OK);
}
private function closeHandlerEvent(event:CloseEvent):void{
this.progressBar.label = "当前进度: 0%";
this.progressBar.visible = false;
//下面这句代码是初始化进度条背景颜色,但没有效果
//this.progressBar.setStyle("trackColors","#0000FF ");
}
private function ioErrorHandler(event:IOErrorEvent):void
{
Alert.show(event.toString(),"提示");
}
MXML代码: