【问题标题】:Loader-Class - SecurityError: Error #2000: No active security contextLoader-Class - SecurityError: Error #2000: No active security context
【发布时间】:2023-12-27 11:26:02
【问题描述】:

我在加载一些图像时尝试“捕捉”这个错误。 以下代码是我的问题的测试用例,以确保周围代码中没有错误。

import flash.events.SecurityErrorEvent;

import flash.display.Loader;
import flash.net.URLRequest;

loadImage ();
function loadImage (): void {
            var _imageLoader = new Loader();
            _imageLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, imageSecurityErrorEventListener);
            var request:URLRequest = new URLRequest("this-image-not-exits.jpg");

            _imageLoader.load(request);
}

function imageSecurityErrorEventListener (e:SecurityErrorEvent) {
    trace ("This is my own trace for the Security Error");
}

我知道 www 和这里有很多帖子和问题,但我找不到我的问题的答案。

我正在制作一部互动电影,其中包含许多在应用程序中动态加载的图像和电影。

在这个片段中,我在我的应用程序中生成了最坏的情况(尝试加载不退出的图像)。 当我运行此代码时,我得到跟踪“SecurityError:错误#2000:没有活动的安全上下文”而不是我的监听器的跟踪。 你知道出了什么问题吗?

【问题讨论】:

    标签: actionscript-3 security flash-cs5 loader


    【解决方案1】:

    该特定安全错误被抛出,而不是作为ErrorEvent 发送。

    可以使用try...catch 块代替检测:

    function loadImage (): void 
    {
        var _imageLoader = new Loader();
        _imageLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, imageSecurityErrorEventListener);
        var request:URLRequest = new URLRequest("this-image-not-exits.jpg");
    
        try
        {
            _imageLoader.load(request);
        }
        catch (error:Error)
        {
            trace("A different error was thrown, not dispatched as an ErrorEvent");
        }
    }
    

    有关作为事件引发或分派的所有错误的完整列表,请参阅 Adob​​e 语言参考页面:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load()

    【讨论】:

    • 当我尝试此操作时,将跟踪相同的错误。您还有其他建议吗?
    • 也许直接听loader而不是它的contentLoaderInfo? _imageLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, imageSecurityErrorEventListener);