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

查看:198
本文介绍了无法从使用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来显示图像,但我需要先缩放图片(喜苏亚雷斯照片)我已经有比例的部分做不同的是,我需要的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.

另外,我有尝试过这样的:

ALSO, I have tried this:

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);

数据也是空!如此令人沮丧。任何帮助将是AP preciated。

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没有经验,但是你的第二个code座显然是错误的。一个的URLRequest 比如什么都不做的本身,它不过是存储请求细节的静态对象。为了从该网址获取数据,你需要创建一个装载机,并请求传递给装载机是这样的:

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 处理程序。请注意,装载机类可用于加载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 块,这里是从的文档

通常的处理程序   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天全站免登陆