如何处理\捕获此错误
Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.
我尝试使用AS3将损坏的图像加载到MovieClip中 我试过用try&抓住但没办法 我也尝试addEventListener
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
但它没有发现此错误
任何帮助?!
答案 0 :(得分:6)
如果要捕获任何看不见的错误,可以使用标准的try-catch块。
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener("complete", ldrDone);
ldr.contentLoaderInfo.addEventListener("ioError", ldrError);
ldr.load(new URLRequest("FILE-NAME-COMES-HERE"));
function ldrDone(evt:*):void
{
//if the file can be loaded into a Loader object, this part runs
var temp:*;
try
{
temp = evt.target.content;
//add it to the stage
stage.addChild(temp);
//this traces whether the loaded content is a Bitmap (jpg, gif, png) or a MovieClip (swf)
var classOfObject:String = flash.utils.getQualifiedClassName(temp);
trace(classOfObject);
}
catch(error:*)
{
trace("some error was caught, for example swf is AS2, or whatever, like Error #2180");
}
}
function ldrError(evt:*):void
{
//if the file can't be loaded into a Loader object, this part runs
trace("this is the error part, Error #2124 won't show up");
}
这会捕获错误,例如您尝试加载的swf是一个旧的swf(与AS2一起发布) - 错误#2180。
如果找不到文件,或者看起来不是任何可加载格式,则运行ioError部分 - 错误#2124。