如何处理未处理的 IOErrorEvent

发布于 2024-11-04 21:25:53 字数 327 浏览 0 评论 0原文

如何处理\捕获此错误

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

我尝试使用 AS3 将损坏的图像加载到 MovieClip 我尝试使用 try &抓住但没办法 我也尝试添加事件监听器,

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

但它没有捕获此错误

有帮助吗?!

How to Handle\catch this error

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

I try to load a corrupted image in to MovieClip with AS3
I tried to use try & catch but no way
I alse try to addEventListener

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

but it doesn't catch this error

Any Help?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2024-11-11 21:25:54

如果您想捕获任何看不见的错误,可以使用标准的 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。

If you want to catch any unseen errors, you can use a standard try-catch block.

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");
}

This catches errors, like the swf you are trying to load is an old swf (published with AS2) - Error #2180.

If the file can't be found, or doesn't look like to be of any of the loadable formats, then the ioError part runs - Error #2124.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文