开发者

Adobe AIR drag and drop directory

Please let me know how can I drag and drop a directory from windows onto Adobe AIR panel. The folde开发者_JAVA百科r has subFolders inside. The subFolders have many files. I want to drag the parent folder and drop it so that the whole structure has to get uploaded. Please help.


It is rather easy to upload folders. When detecting a drop using the drop event, you get supplied wit ha list of files dropped. You can then determine if it is the dropped file is a folder, and if it is, then you can get all the files listed under it (which includes files) and if any of those are folders, then recurse further down.

Basically, adobe air treats files and folders as the same object.

In the drop event put

var files = event.dataTransfer.getData( "application/x-vnd.adobe.air.file-list" );

    var fileData = [];
    for (var f = 0; f < files.length; f++)
    {
        if (files[f].isDirectory) {
                //process this folder recursing through subfolders
        } else {
                //we have a file
        }
    }

You can then recurse through the object adding files and files to the server as needed


Here is the complete Example. Just call onInit() method on application's initialization.

private function onInit(event:FlexEvent):void
{
    this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
    this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDrop);
}

private function onDragIn(event : NativeDragEvent):void
{
    NativeDragManager.acceptDragDrop(this);
}

private function onDrop(event : NativeDragEvent):void
{
    try
    {
        var dropfiles:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
        processDroppedFiles(dropfiles);
    }
    catch (error : IOError)
    {
        trace("Error during drag-and-drop procedure.");
    }
}

private function processDroppedFiles(files : Array):void
{
    for each (var file:File in files)
    {
        if (file.isDirectory)
        {
            processDirectory(file);
        }
        else
        {
            processFile(file);
        }
    }
}

private function processDirectory(dir : File):void
{
    processDroppedFiles(dir.getDirectoryListing());
}

private function processFile(file:File):void
{
    trace(file);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜