<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import flash.net.FileReference;
[Bindable]
[Embed('com/cheping/assets/document.png')]
private var diskIcon:Class;
[Bindable]
private var arrColl:ArrayCollection;
/* URL of the file to download. */
private const FILE_URL:String = "http://192.168.1.9/flex.rar";
private var fileRef:FileReference;
private var urlReq:URLRequest;
private function init():void {
/* Initialize the array collection to an empty collection. */
arrColl = new ArrayCollection();
/* Set up the URL request to download the file specified by the FILE_URL variable. */
urlReq = new URLRequest(FILE_URL);
/* Define file reference object and add a bunch of event listeners. */
fileRef = new FileReference();
fileRef.addEventListener(Event.CANCEL, doEvent);
fileRef.addEventListener(Event.COMPLETE, doEvent);
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 {
/* Create shortcut to the FileReference object. */
var fr:FileReference = evt.currentTarget as FileReference;
/* Add event order and type to the DataGrid control. */
arrColl.addItem({data:arrColl.length+1, type:evt.type, eventString:evt.toString()});
try {
/* Update the Model. */
fileRefModel.creationDate = fr.creationDate;
fileRefModel.creator = fr.creator;
fileRefModel.modificationDate = fr.modificationDate;
fileRefModel.name = fr.name;
fileRefModel.size = fr.size;
fileRefModel.type = fr.type;
/* Display the Text control. */
txt.visible = true;
} catch (err:*) {
/* uh oh, an error of sorts. */
}
}
private function downloadSourceCodeZip():void {
/* Clear existing array collection. */
arrColl = new ArrayCollection();
/* Hide the Text control. */
txt.visible = false;
/* Begin download. */
fileRef.download(urlReq);
// fileRef.s
// Alert.show( Application.application.url);
}
private function showAlert(item:Object):void {
Alert.show(item.eventString, item.type);
}
]]>
</mx:Script>
<mx:Model id="fileRefModel">
<file>
<creationDate>{""}</creationDate>
<creator>{""}</creator>
<modificationDate>{""}</modificationDate>
<name>{""}</name>
<size>{""}</size>
<type>{""}</type>
</file>
</mx:Model>
<mx:Button id="downloadBtn" label="Download example source code" icon="{diskIcon}" click="downloadSourceCodeZip()" toolTip="{FILE_URL}" height="40" />
<mx:DataGrid id="debug" dataProvider="{arrColl}" width="{downloadBtn.width}" rowCount="5" rowHeight="22" itemClick="showAlert(event.currentTarget.selectedItem)">
<mx:columns>
<mx:DataGridColumn dataField="data" headerText="#" width="20" />
<mx:DataGridColumn dataField="type" headerText="Type" showDataTips="true" dataTipField="eventString" />
</mx:columns>
</mx:DataGrid>
<mx:Text id="txt" condenseWhite="true" visible="false">
<mx:text>
creationDate: {fileRefModel.creationDate}
creator: {fileRefModel.creator}
modificationDate: {fileRefModel.modificationDate}
name: {fileRefModel.name}
size: {fileRefModel.size}
type: {fileRefModel.type}
</mx:text>
</mx:Text>
</mx:Application>
分享到:
相关推荐
在项目开发过程中,经常会遇到文件上传下载的...但在flex中由于安全沙箱的原因flex程序不能直接访问本地文件,但是flex SDK中提供了FileReference和FileReferenceList两个类,可以通过这两个类来实现文件的上传下载。
实现文件上传下载到数据中,有上传精度条显示,可以上传MP3,MP4,txt等各种文件,可以再线浏览txt,word,excel等文件。
Mobile FLEX到指定URL下载数据
Flex和Servlet结合使用,文件上传、下载
本文所有资料均来自Flex官方文档,其英文版权归 Adobe公司所有。 均有实例代码讲解
flex文件上传下载,web项目添加flex操作,进行文件上传,下载操作,代码型
1、介绍flex的用法、配置、语法等 2、flex的使用文档说明
/********************* Flex 指定文件下载 带进度条 **********************/
flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助文档flex 中文帮助...
flex中文帮助文档flex中文帮助文档
2. 本文所有资料均来自Flex 官方文档,其英文版权归Adobe 公司所有。 3. 文中某些内容根据译者的理解稍作改动,因此与原版英文在文字上不完全一致。同时,由于译者水平有限,翻译不妥之处请大家多多见谅。
flex文档 ActonScript3.0 flex4各类电子书
Flex文件的上传下载.Flex文件的上传下载.Flex文件的上传下载.Flex文件的上传下载.Flex文件的上传下载.
本文档包含了详细的Flex技术讲解,对Flex入门的学习者用处很大。
相当经典啦Flash地图控件类,其实例对象可以嵌入到网页、Flex或AIR应用程序中形成交互地图
Flex中文版的教程,从Flex 官方文档翻译过来。
Flex学习文档,Flex中文文档,,记载了各种学习心得
Flex帮助文件 Flex帮助文件 Flex帮助文件 Flex帮助文件 Flex帮助文件