- 积分
- 136401
- 注册时间
- 2014-12-27
- 最后登录
- 2026-1-23
- 在线时间
- 605 小时
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
- 交易凭证
- 1
- 分享
- 0
- 精华
- 33
- 帖子
- 2094
- 主题
- 1742
TA的每日心情 | 擦汗 2018-4-10 15:18 |
|---|
签到天数: 447 天 [LV.9]以坛为家II
超级版主
    
- 威望
- 562
- 贡献
- 29
- 金币
- 52903
- 钢镚
- 1422
 
|
1. 把文件从本地操作系统拖入AIR客户端程序.实际上是上传文件到服务器的过程。
- <?xml version="1.0" encoding="utf-8"?>
- <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx" nativeDragDrop="dropFile(event)"
- nativeDragEnter="startDrag2(event)" creationComplete="init()"
- >
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- private function init():void
- {
- }
-
- private function startDrag2(event:NativeDragEvent):void
- {
- var clip:Clipboard = event.clipboard;
- if(clip.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
- {
- var arr:Array = clip.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
- }
- NativeDragManager.acceptDragDrop(this);
- }
-
- private function dropFile(event:NativeDragEvent):void
- {
- var clip:Clipboard = event.clipboard;
- if(clip.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
- {
- var arr:Array = clip.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
- var file:File = arr[0] as File;
- if(file.isDirectory)
- {
- var fileLst:Array = file.getDirectoryListing();
- }
- }
- }
- ]]>
- </fx:Script>
- </s:WindowedApplication>
复制代码 在dropFile函数中,可以得到剪贴板中所有正在拖动的本地文件引用(flash.filesystem.File),有了这些本地文件引用后,就可以用如下方法,把本地文件上传到服务器了。- flash.net.FileReference.upload(request:URLRequest, uploadDataFieldName:String="Filedata", testUpload:Boolean=false):void
复制代码 2. 把AIR客户端中的文件拖放到(下载到)本地操作系统。实际上是文件下载的过程
- var file_promise_array:Array = [];
- var cb:Clipboard = new Clipboard();
- var fp:URLFilePromise = new URLFilePromise();
- var drag_component:DisplayObject;
- fp.request = new URLRequest((renderer.data as FileVO).resource_url);
- fp.request.manageCookies = false;
- fp.relativePath = (renderer.data as FileVO).name;
- //fp.addEventListener(ProgressEvent.PROGRESS, fpProgressHandler); //fp.addEventListener(IOErrorEvent.IO_ERROR, fpIOErrorHandler); file_promise_array.push(fp);
- if (file_promise_array && file_promise_array.length)
- cb.setData(ClipboardFormats.FILE_PROMISE_LIST_FORMAT, file_promise_array);
- var bd:BitmapData = new BitmapData(drag_component.width, drag_component.height, true, 0x000000);
- bd.draw(drag_component);
- var ndo:NativeDragOptions = new NativeDragOptions();
- ndo.allowMove = false;
- ndo.allowCopy = true;
- ndo.allowLink = false;
- NativeDragManager.doDrag(drag_component, cb, bd, null, ndo);
复制代码 URLFilePromise 是封装度相当高的类,文件何时开始下载,无法通过程序来控制,当文件被用户从AIR程序中拖放到本地桌面或者文件夹后,下载过程自动开始,这点上和URLLoader类是大不相同地。在用URLLoader类下载东西时,必须先指定好下载路径(URLRequest),再显式调用URLLoader类 的load()方法,下载过程才会开始,程序是可以控制URLLoader 何时开始下载的,URLFilePromise 类何时开始下载,取决于用户何时完成拖放操作。
创建 URL file promise:- 构建并初始化一个或多个 URLFilePromise 对象。
- 将 URLFilePromise 对象添加到数组。
- 使用 ClipboardFormat FILE_PROMISE_LIST 为新 Clipboard 对象添加数组。
- 响应用户手势,调用 NativeDragManager startDrag() 方法,传递包含 file promise 数组的 Clipboard 对象。
参考:
http://help.adobe.com/zh_CN/Flas ... URLFilePromise.html
http://help.adobe.com/en_US/Flas ... ktop/Clipboard.html
来源:
Air应用中的文件拖放
http://bbs.9ria.com/forum.php?mod=viewthread&tid=149716&fromuid=229622
|
|