Adobe AIR 拖放目录

发布于 2024-08-07 08:31:05 字数 92 浏览 1 评论 0原文

请告诉我如何将目录从 Windows 拖放到 Adob​​e AIR 面板上。 该文件夹内有子文件夹。子文件夹有很多文件。 我想拖放父文件夹,以便上传整个结构。 请帮忙。

Please let me know how can I drag and drop a directory from windows onto Adobe AIR panel.
The folder 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜血缘 2024-08-14 08:31:05

上传文件夹相当容易。当使用 drop 事件检测到删除时,您将获得已删除文件的列表。然后,您可以确定删除的文件是否是文件夹,如果是,则可以获取其下列出的所有文件(包括文件),如果其中任何一个是文件夹,则进一步向下递归。

基本上,adobe air 将文件和文件夹视为同一对象。

在 drop 事件中 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
        }
    }

然后可以通过对象递归根据需要添加文件和文件到服务器

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

颜漓半夏 2024-08-14 08:31:05

这是完整的示例。只需在应用程序初始化时调用 onInit() 方法即可。

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文