从 applicationStorage 目录添加图像

Add image from applicationStorage directory

我正在为 animate cc 中的 android 和 ios 创建一个 as3 应用程序。 我的问题是我无法将图像从 applicationStorageDIrectory 添加到舞台,我唯一能做的就是列出它们:

var desktop:File = 

File.applicationStorageDirectory.resolvePath("imgFlussi/set");
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++)
{
 trace(files[i].nativePath); // gets the path of the files
 trace(files[i].name);// gets the name
}

这是我尝试添加图像的代码: imgLoader =

imgLoader = File.applicationStorageDirectory.resolvePath("imgFlussi/set/"+valImg+".jpg") as DisplayObject;
cont.addChild(imgLoader); 

你的错误是 File.applicationStorageDirectory.resolvePath(...) returns 一个 File 实例,而不是一个显示对象。为了让它工作,你需要创建一个 Loader 实例并实际从文件中加载它:

var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest;

aRequest.url = "app-storage:/imgFlussi/set/" + valImg + ".jpg";
aLoader.load(aRequest);
cont.addChild(aLoader);