Adobe Air :: Files Drag and drop into application

閲覧: 90 回
最初の未読メッセージにスキップ

fuoco

未読、
2008/10/24 9:18:122008/10/24
To: Bulgaria Flex User Group
Hello.
I would like to show an easy way to drag and drop files from
filesystem within your Air applications.
The well-known technology Drag And Drop allows users to drag file or
files list and drop it or them on several component of your Air
Application.

Let we have a panel:

<mx:Panel />

In order to make this panel accept files being dragged and dropped
over it, we handle these events:

<mx:Panel
nativeDragEnter="onDragIn(event)"
nativeDragDrop="onDrop(event)"
/>


The first event nativeDragEnter is a good point to set the mouse
cursor by putting this code in it:

public function onDragIn(event:NativeDragEvent):void
{
if (event.clipboard.hasFormat('air:file list')) // only accept files
list
DragManager.acceptDragDrop(this); // set the "+" mouse cursor
}

The second event nativeDragDrop is the adequate place to read the
files being dropped:

public function onDrop(event:NativeDragEvent):void
{
var dropfiles:Array =
event.clipboard.getData('air:file list') as Array;

for each (var file:File in dropfiles)
{
importFile(file);
}
}

Comment: the clipboard field of the NativeDragEvent argument does not
seem to have anything common with the windows clipboard holder's
content.

Finally you have access to the imported files by the dropfiles array,
get as a clipboard data format 'air:file list'.

Hope this to be helpful if someone needs to import files using drag
and drop.
全員に返信
投稿者に返信
転送
新着メール 0 件