as3 Air browse for file on sd card?

后端 未结 2 1946
我在风中等你
我在风中等你 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();
                }
            }
        }
    }
    

提交回复
热议问题