as3 Air browse for file on sd card?

后端 未结 2 1945
我在风中等你
我在风中等你 2021-01-17 04:58

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

This code only pops up an upload box and says \"No Files were foun

相关标签:
2条回答
  • 2021-01-17 05:21

    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();
                }
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-17 05:37

    I gave you an answer here: as3 get zip file on phone from app - file path then unzip

    Basically you have to write your own file browser, help documentation suggests this (however they could built it in). e.g.

    var rootDirs:Array = File.getRootFirectories();//all available root dirs
    

    then you can pick one and lists it's content

    if(rootDirs && rootDirs.length > 0)
    {
        var dir:File = rootDirs[0]
        if(dir.isDirectory)
        {
            //try to enumerate it's content
    
            var files:Array = dir.getDirectoryListing();
    
        }
    }
    

    best regards

    0 讨论(0)
提交回复
热议问题