开发者

Loader-Class - SecurityError: Error #2000: No active security context

I try to "catch" this error when I'm loading some images. The following code is an test-case for my problem to secure that there are no errors in the surrounding code.

import flash.events.SecurityErrorEvent;

import flash.d开发者_如何学Goisplay.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");
}

I know that there are lot's of posts and questions in the www and here, but I couldn't find an answer to my problem.

I'm working on an interactiv-movie with many images and movies which are loaded dynamically in the application.

In this snipped I generated the worst case in my application (try to load an image that not exits). When I run this code I get the trace "SecurityError: Error #2000: No active security context" and not the trace of my the Listener. Do you have any idea whats going wrong?


That specific security error is thrown rather than dispatched as an ErrorEvent.

It can be detected by using a try...catch block instead:

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

For a full list of all errors thrown or dispatched as Events, see the Adobe language reference page: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜