내 앱에서 일부 외부 swf 파일을로드해야합니다. 다음 코드를 사용했습니다.손상된 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 파일 중 일부가 손상된 것으로 나타났습니다. 이러한 파일을로드 할 때 complete 이벤트를 전달하지 않으며 오류도 발생시키지 않습니다. 그래서, 내 질문은 거기에 swf 파일이 손상되었는지 찾을 수있는 방법이 무엇입니까? 네, 그 손상된 swf 파일을 대체 할 수 있습니다. 이런 종류의 문제가 다시 발생하면 예방 조치에 불과합니다. 현재 내가 생각할 수있는 것은 타이머를 작성하고 complete 이벤트가 디스패치인지 아닌지를 확인하는 것입니다. 그렇지 않다면 쇼는 파일 메시지를 읽을 수 없습니다. 이 문제를 해결할 더 좋은 방법이 있습니까?
파일의 무결성을 테스트하려면 파일을 해시하고 결과를 예상 값과 비교하십시오. 피 묻은 암호 라이브러리가 권장됩니다. – seventeen
설명서에 그러한 상황에 대한 IO_ERROR 이벤트가 명시되어 있습니다. – Organis
@Organis, IO_ERROR가 실행되지 않았습니다. 크기의 파일이 0 일 때만 시작됩니다. – TheGunners