AS2:LoadMovieClip.onError 似乎没有捕获一些错误

发布于 2024-08-27 04:32:26 字数 1446 浏览 3 评论 0原文

我有一些通过 HttpHandler 打开 SWF 文件的 AS2 代码。

我试图让程序识别所请求的文件何时丢失。

我的第一次尝试涉及使用 LoadVars 和“load”,并且仅在文件成功加载时才调用 loadMovie(在此处找到了该技术)。但是,我发现当文件确实存在时,HttpHandler 中的 ProcessRequest 函数会被调用两次。有意义 - 一次用于加载,一次用于 loadMovie。

现在我改用 MovieClipLoader (也在这里找到了这种技术)。无论是否找到文件,这种方式都只调用一次 ProcessRequest。但我的问题是 onLoadError 函数只有在我给它一个错误的 URL 时才起作用。如果我给它一个好的 URL,将错误的文件名传递给处理程序,则处理程序会抛出错误,但我的 onLoadError 函数似乎没有意识到存在问题 - 我只是得到一个空白区域,其中应显示错误消息向上。

这是相关的 AS2 代码:

function CheckFileExists(inFile) {

    var mclListener:Object = new Object();
    mclListener.onLoadError = function(target_mc:MovieClip, err:String){
         if(err=="URLNotFound")
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "URL not found: \n\t" + target_mc._url;
         }
         else //I would expect this block to handle the error, since the URL is good.
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "some other problem: \n\t" + target_mc._url;
         }
    }

    var mcl:MovieClipLoader = new MovieClipLoader();
    mcl.addListener(mclListener);
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mcl.loadClip(inFile, mc);
}

有什么帮助吗?

I have some AS2 code that opens a SWF file through an HttpHandler.

I'm trying to get the program to recognize when a requested file is missing.

My first attempt involved using LoadVars and "load", and only calling loadMovie if the file successfully loaded (found the technique somewhere out here). However, I found that the ProcessRequest function in the HttpHandler was getting called twice when the file does exist. Makes sense - once for load, once for loadMovie.

Now I'm using MovieClipLoader instead (also found this technique out here). This way does call ProcessRequest only once whether or not the file is found. But my problem is that the onLoadError function is only working when I give it a bad URL. If I give it a good URL that passes a bad filename to the handler, the handler throws an error, but my onLoadError function doesn't seem to recognize that there's a problem - I just get a blank area where the error message should be showing up.

Here's the relevant AS2 code:

function CheckFileExists(inFile) {

    var mclListener:Object = new Object();
    mclListener.onLoadError = function(target_mc:MovieClip, err:String){
         if(err=="URLNotFound")
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "URL not found: \n\t" + target_mc._url;
         }
         else //I would expect this block to handle the error, since the URL is good.
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "some other problem: \n\t" + target_mc._url;
         }
    }

    var mcl:MovieClipLoader = new MovieClipLoader();
    mcl.addListener(mclListener);
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mcl.loadClip(inFile, mc);
}

Little help?

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

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

发布评论

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

评论(1

人疚 2024-09-03 04:32:26

您的服务器功能如何抛出错误?确保它返回实际的 HTTP 错误代码,例如 404 或 503 等。如果它以文本消息的形式返回 HTTP 状态代码 200 和错误,则 Flash 不知道这是一个错误。它只看到状态 200 并认为加载正常,并尝试将数据作为 Flash 影片加载。

How is your server function throwing an error? Make sure it returns an actual HTTP error code like 404 or 503 or something. If it's returning HTTP status code 200 with an error as a text message, then Flash does not know this is an error. It just sees the status 200 and thinks the load is fine, and attempts to load the data as a flash movie.

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