as3 Air 浏览 sd 卡上的文件? [英] as3 Air browse for file on sd card?

查看:39
本文介绍了as3 Air 浏览 sd 卡上的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望能够使用 as3 air 从用户手机中浏览和选择文件.

Looking to be able to have access to browse and select a file from the users phone using as3 air.

此代码仅弹出一个上传框并显示未找到文件".但我知道我的手机上有一个 zip,所以它一定没有选择正确的文件夹路径.如何更改它以使其访问整个手机?

This code only pops up an upload box and says "No Files were found". But I know I have a zip on my phone so it must not be choosing the right folder path. How can I change that to make it access the entire phone?

function unzip_init():void{

    fileFilter = new FileFilter("selected your zip file.", "*.zip; *.gz2; *.bz2;");
    file = new File();
    //file.browseForDirectory("Choose a directory"); // Only got me the directory path
    file.browseForOpen("Open", [fileFilter]);
    file.addEventListener(Event.SELECT, onSelectedFile);
}

推荐答案

从SD卡中获取所有mp3文件

To get all the mp3 files from the SD card

var ROOT:File = File.documentsDirectory.resolvePath("/sdcard/");
var FILES:Array = ROOT.getDirectoryListing();
var TrackN:int;
var SUBFOLDER:String;

for (var i:int = 0; i < FILES.length; i++)
{
    var File_Ext:String;
    File_Ext = "" + FILES[i].extension;

    if (File_Ext.toLowerCase() == "mp3")
    {
      TrackN++;
      list.addItem( { label:FILES[i].name, data:TrackN, Song:FILES[i].url} );
    }

    if (FILES[i].isDirectory == true)
    {
      SUBFOLDER = "" + FILES[i].nativePath;
      getSubfolders();
    }

    function getSubfolders()
    {
        var SUBF:File = File.documentsDirectory.resolvePath(SUBFOLDER);
        var FLIST:Array = SUBF.getDirectoryListing();

        for (var s:int = 0; s < FLIST.length; s++)
        {
            File_Ext = "" + FLIST[s].extension;

            if (File_Ext.toLowerCase() == "mp3")
            {
                TrackN++;
                list.addItem( { label:FLIST[s].name, data:TrackN, Song:FLIST[s].url} );
            }

            if (FLIST[s].isDirectory == true)
            {
                SUBFOLDER = "" + FLIST[s].nativePath;
                getSubfolders();
            }
        }
    }
}

这篇关于as3 Air 浏览 sd 卡上的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆