【发布时间】:2018-02-17 00:45:45
【问题描述】:
在我的应用程序中,我需要加载一些外部 swf 文件。我使用了以下代码:
var file:File;
file = File.documentsDirectory.resolvePath("myfolder/myfile.swf");
if(file.exists)
{
var inFileStream:FileStream = new FileStream();
inFileStream.open(file, FileMode.READ);
var swfBytes:ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();
var loaderContext:LoaderContext = new LoaderContext(false, new ApplicationDomain(null));
loaderContext.allowLoadBytesCodeExecution = true;
loaderContext.allowCodeImport = true;
myLoader = new Loader();
try
{
myLoader.loadBytes(swfBytes, loaderContext);
}
catch(e:Error)
{
trace("Can't read file.");
}
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadComplete_swf);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop, false, 0, true);
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadingError);
}
else
{
trace("File doesn't exists.");
}
一切正常。但我最近发现我的一些 swf 文件已损坏。加载这些文件时,它不会调度完成事件,也不会引发任何错误。所以,我的问题是,有没有办法找到 swf 文件是否损坏?是的,我可以替换那些损坏的 swf 文件。如果此类问题再次发生,这只是一种预防措施。目前,我能想到的就是创建一个计时器并检查是否已调度完成事件。如果不是,则显示无法读取文件消息。有没有更好的处理方法?
【问题讨论】:
-
测试文件哈希的完整性并将结果与您的预期值进行比较。推荐血腥加密库。
-
文档说明这种情况是 IO_ERROR 事件。
-
@Organis,IO_ERROR 没有触发。它仅在文件大小为零时触发。
-
@TheGunners 我刚刚检查并确认了它。如果源字节不代表有效的 SWF、JPG、PNG 或任何其他适合 Loader 的格式,它确实会触发 IO_ERROR。这意味着您的文件在格式方面没有损坏。
标签: android actionscript-3 flash