`
那夜温柔低调
  • 浏览: 20380 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flex 文件下载

    博客分类:
  • flex
阅读更多
<?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/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.events.*;

import mx.controls.Alert;
import mx.events.FlexEvent;
private var downloadURL:URLRequest;
private var file:FileReference; //这是要主要的地方
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
}

public function download():void {
var url:String=encodeURI("http://192.168.1.190:8080/epolice/201207/01/101A0001/2012063017124026101A000141.jpg");               

downloadURL = new URLRequest(url);

file = new FileReference();
configureListeners(file);
file.download(downloadURL,"xx1x.jpg");//此处为文件名

}

private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.CANCEL, cancelHandler);
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(Event.SELECT, selectHandler);



}

private function cancelHandler(event:Event):void {

trace("cancelHandler: " + event);
}

private function completeHandler(event:Event):void {
/* Alert.show("下载完成"); */
trace("completeHandler: " + event);
}

private function ioErrorHandler(event:IOErrorEvent):void {

trace("ioErrorHandler: " + event);
}

private function openHandler(event:Event):void {

trace("openHandler: " + event);
}

private function progressHandler(event:Event):void {
var file:FileReference = FileReference(event.target);

//trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}

private function securityErrorHandler(event:SecurityErrorEvent):void {

trace("securityErrorHandler: " + event);
}

private function selectHandler(event:Event):void {

var file:FileReference = FileReference(event.target);
trace("selectHandler: name=" + file.name + " URL=" + downloadURL.url);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>



<mx:HRule x="10" y="49" width="80%"/>

<mx:Button x="10" y="75" label="Download HTML Component" click="{download()}"/>
</s:Application>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics