2011-05-05 52 views
3

如何处理\赶上这个错误如何处理未处理的IOErrorEvent

Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type. 

我尝试到影片剪辑加载一个损坏的图像与AS3 我试图用尽量&抓但没办法 我ALSE尝试的addEventListener

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError); 

但它并没有赶上这个错误

任何帮助?

+0

onIOError侦听器函数是否存在?你在使用URLLoader吗? – DanielB 2011-05-05 08:32:16

+0

是的我已经创建onIOError函数,是的,我使用URLLoader,它加载图像时工作正常,但当我使用损坏的图像我无法处理错误 – JustMe 2011-05-05 08:36:54

+0

尝试使用'URLStream':http://help.adobe。 com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLStream.html – www0z0k 2011-05-05 08:48:31

回答

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。

+0

只是添加到您的答案...我不知道2011年,但今天,与AirSDK 19,IOErrorEvent.IO_ERROR确实缓存损坏的图像#2124错误消息。 – MyFlashLab 2015-10-25 16:16:54

相关问题