Android-AS3 Air浏览SD卡上的文件?
作者:互联网
希望能够使用as3 air从用户手机中浏览和选择文件.
此代码仅弹出一个上传框,并显示“未找到文件”.但是我知道我的手机上有一个zip,所以它一定不能选择正确的文件夹路径.如何更改它以使其能够访问整个手机?
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文件
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();
}
}
}
}
标签:android,actionscript-3,air 来源: https://codeday.me/bug/20191010/1885057.html