在Air for Android settings的" Include files "部分,我将test1.swf和test2.swf添加到自动包含的主文件中。
myLoader.load(new URLRequest("test1.swf")
或者,还有其他文件夹我应该包括吗?以下是正确的吗?
myLoader.load(new URLRequest("....test1.swf")
我现在无法在Android上测试这个,但我相信包含的文件放在应用程序目录中,您可以通过以下方式访问:
var path:String = File.applicationDirectory.resolvePath("test1.swf").nativePath;
myLoader.load(new URLRequest(path));
也可以使用简写url:
myLoader.load(new URLRequest("app://test1.swf"));
您还可以使用FileStream
类加载swf,这可以为您提供更多的控制。它看起来像这样:
var file:File = File.applicationDirectory.resolvePath("test1.swf");
if (file.exists) {
var swfData:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
stream.readBytes(swfData);
stream.close();
var myLoader:Loader = new Loader();
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
myLoader.loadBytes(swfData, loaderContext);
addChild(myLoader);
}else {
trace("file doesn't exist");
}