您好,感謝您預先的任何幫助...AS3 Android的AIR文件路徑
我有以下功能應在應用程序存儲目錄中的子文件夾顯示所有圖像:
public function mygallery():void
{
var gallery:File = File.applicationStorageDirectory.resolvePath("IMAGES/");
var gfiles:Array = gallery.getDirectoryListing();
var gcount:int = 0;
gcount = gfiles.length;
var x_counter:Number = 0;
var y_counter:Number = 0;
createContainer();
callThumbs();
function createContainer():void
{
container_mc = new MovieClip();
container_mc.x = gx;
container_mc.y = gy;
//container_mc.width = gthumbw;
//container_mc.height = gthumbh;
addChild(container_mc);
}
function callThumbs():void
{
for (var j:uint = 0; j < gcount; j++)
{
var thumb_url = gfiles[j].nativePath;
var thumb_loader = new Loader();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
thumb_loader.x = (gthumbw+gspw)*x_counter;
thumb_loader.y = (gthumbh+gsph)*y_counter;
if (x_counter+1 < gcol)
{
x_counter++;
}else
{
x_counter = 0;
y_counter++;
}
//trace(gfiles[j].nativePath);
}
}
function thumbLoaded(e:Event):void
{
var my_thumb:Loader = Loader(e.target.loader);
my_thumb.width = gthumbw;
my_thumb.height = gthumbh;
container_mc.addChild(my_thumb);
}
}
gcount返回文件夾中正確數量的文件,但由於某些原因圖像根本不顯示。
當我在Windows中運行它時,它工作正常,這導致我相信它是Android的沙盒問題,或者我錯誤地使用文件路徑。
任何意見是極大的讚賞
嗯,你可以通過監聽對裝載機的替代只是一個完整的事件錯誤開始。請參閱我的答案的第一部分[此處](http://stackoverflow.com/a/32077648/1457439)。另外,AS3中最好避免使用內聯函數。 – BadFeelingAboutThis
嘿,謝謝您的幫助......這裏的總諾伊請原諒我的無知。當我收聽IOErrorEvent時,出現錯誤#2035。那麼我將如何指向路徑呢? 「app-storage:// IMAGES/?? – cnapsys
如果你使用'gFiles [j] .url'而不是'gFiles [j] .nativePath',它可能會工作。本地路徑更多的是'File'& 'FileStream'類(對於本地文件來說可能更好),url更適用於使用'file:'方案限制沙盒的Loader。 – BadFeelingAboutThis