Adobe Air :: Files Drag and drop into application

90 visualizações
Pular para a primeira mensagem não lida

fuoco

não lida,
24 de out. de 2008, 09:18:1224/10/2008
para 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.
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem