无法使用 Flex 从剪贴板获取文件数据 [英] Cannot get file data from the clipboard using Flex

查看:24
本文介绍了无法使用 Flex 从剪贴板获取文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:具有以下事件的 Flex TileList:

Given: A Flex TileList with the following event:

<mx:nativeDragDrop>
  <![CDATA[
    if(event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)) {
      var files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;

      for each(var file:File in files)
      {
        // file.data is null here!
      }

      this.listData.refresh();
    }
  ]]>
</mx:nativeDragDrop>

我正在尝试从拖入此 TileList 的 jpeg 创建缩略图列表.Image.source 可以使用 url 来显示图像,但我需要先缩小图像(嗨 rez 照片)我已经完成了缩放部分,只是我需要文件中的 BitmapData 并且它为 file.data 为空.

I am trying to create a list of thumbnails from jpegs that I drag into this TileList. Image.source can use the url to show the image, but I need to scale the image down first (hi rez photos) I already have the scaling part done except that I need BitmapData from the file and it has null for file.data.

另外,我试过这个:

var x:URLRequest = new URLRequest(value.file.url); // this is a local file (e.g. file:///C:/somefile.jpg)
var b:Bitmap = new Bitmap(x.data as BitmapData);

数据也为空!太令人沮丧了.任何帮助将不胜感激.

data is ALSO null! So frustrating. Any help would be appreciated.

推荐答案

我假设这是 AIR 应用程序的一部分.(无法从普通 Flex 应用程序访问剪贴板.)

I assume this is a part of an AIR application. (Accessing the clipboard from a plain Flex app is not possible.)

我没有使用 AIR 的经验,但是您的第二个代码块显然是错误的.URLRequest 实例本身什么都不做,它只是一个存储请求细节的静态对象.为了从该 URL 获取数据,您需要创建一个 Loader,并将请求传递给该加载器,如下所示:

I have no experience with AIR, but your second code block is clearly wrong. An URLRequest instance does nothing in itself, it is but a static object storing the request details. In order to fetch the data from that URL, you need to create a Loader, and pass the request to that loader like this:

var req:URLRequest = new URLRequest(value.file.url); // this is a local file (e.g. file:///C:/somefile.jpg)
var ldr:Loader = new Loader();
ldr.addEventListener(Event.COMPLETE, function(event:Event):void {
   var b:Bitmap = event.target.content as Bitmap;
});
ldr.load(req);

当然,您必须填写 Event.COMPLETE 处理程序.请注意,Loader 类可用于加载 SWF 和图像对象,对于其他所有内容,您必须使用 URLLoader 并自己解析数据.

Of course, you'd have to fill in the Event.COMPLETE handler. Note that the Loader class can be used to load SWF and image objects, for all everything else, you'd have to use URLLoader and parse the data yourself.

关于 nativeDragDrop 块,这里是 文档的片段:

Regarding the nativeDragDrop block, here's a snippet from the documentation:

通常是一个处理程序nativeDragEnter 或 nativeDragOver事件评估数据拖动,以及拖动动作允许,以确定是否交互式对象可以接受放置.指定一个交互式对象是一个合格的目标,事件处理程序必须调用NativeDragManager.acceptDrop()函数,传入对物体.如果用户释放鼠标按钮在指定的物体,物体变成水滴目标并派遣nativeDragDrop 事件.

Typically a handler for the nativeDragEnter or nativeDragOver event evaluates the data being dragged, along with the drag actions allowed, to determine whether an interactive object can accept a drop. To specify that an interactive object is an eligible target, the event handler must call the NativeDragManager.acceptDrop() function, passing in a reference to the object. If the user releases the mouse button over the designated object, the object becomes the drop target and dispatches the nativeDragDrop event.

您是否正确调用了 NativeDragManager.acceptDrop()?

这篇关于无法使用 Flex 从剪贴板获取文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆