SecurityError: Error #2000: No active security context.

SecurityError: Error #2000: No active security context.

Description:
The SecurityError exception is thrown when some type of security violation takes place.

Examples of security errors:

* An unauthorized property access or method call is made across a security sandbox boundary.
* An attempt was made to access a URL not permitted by the security sandbox.
* A socket connection was attempted to an unauthorized port number, e.g. a port above 65535.
* An attempt was made to access the user’s camera or microphone, and the request to access the device was denied by the user.

In this case the error message says the security context is inactive for the given operation (and possibly denied because of this ambiguity).

I’ve come across this with calls to setTimeout, methods on the File Reference class and navigateToURL. It may also occur when a SWF created for AIR is run from a web page. It has been noted elsewhere that this is a known bug in the Flash Player 10? dealing with the scope. The file referenced may also be missing.

This also occurred randomly for example, when creating a reference to the Capabilities class:

[as]var cap:* = Capabilities;[/as]

As for a cause it is likely a call is being made out of the current sandbox before the Flash Player has a chance to setup a security policy. That may be why delaying a call with setTimeout has been known to fix it. It may also occur when running from the file system instead of from a server (file:// vs http://localhost or http://domain.com).

Occasionally after multiple testing the error disappears. It may be Flash Builder didn’t or couldn’t give permissions to swf in time (file was locked?).

Please post your scenarios.

Some solutions:
For errors that occur when you are using setTimeout already try using callLater (on UIComponent) or wrapping the call in an anonymous function like so:

[as]setTimeout( function():void{fileReference.load();}, 1);[/as]

For file references verify the file is there. One way is to try to embed the file. If the file path is incorrect an error will be thrown at compile time.

Give it more time or a reference in the local scope:

[as]
// does not work
loader.load( new URLRequest(“assets/013.jpg”) );

// works
var request:URLRequest = new URLRequest(“assets/013.jpg”)
loader.load( request );
[/as]

Also try restarting your environment or making changes (resave or clean) and then debug again.

more info…

8 thoughts on “SecurityError: Error #2000: No active security context.

  1. I found that making a reference to full url worked best:

    private function loadSWF(e:Event):void
    {
    isabelleLoader.load(new URLRequest(getBaseURL()+”mySWF.swf”));
    }

    private function getBaseURL():String
    {
    var ldrURL:Array=stage.loaderInfo.url.split(“/”);
    ldrURL.pop();
    var base:String=ldrURL.join(“/”)+”/”;
    return base;
    }

    Like

  2. THANK YOU SOO MUCH !
    This solved my problem :

    var request:URLRequest = new URLRequest(“assets/013.jpg”)
    loader.load( request );

    instead of
    loader.load( new URLRequest(“assets/013.jpg”) );

    Like

  3. I noticed that for urls that you don’t have permission to load, simply attaching a listener to the SecurityErrorEvent prevents the exception from being thrown. e.g.

    loader = new Loader();
    loader.contentLoaderInfo.addEventListener(
    Event.INIT, onLoaderInit);
    loader.contentLoaderInfo.addEventListener(
    SecurityErrorEvent.SECURITY_ERROR, onLoaderError);
    loader.load(new URLRequest(url));

    protected function onLoaderInit(e:Event):void {
    trace(“onLoaderInit”);
    }
    protected function onLoaderError(e:Event):void {
    trace(“onLoaderError”);
    }

    Like

  4. I have a dell Inspiron 1545 with recently installed Vista. I keep getting the message “An ActionScript error has occurred Security Error #2000. No active security”
    I am a dumb old fart but I read you pages about this error and did not understand what I am to do. Please help.

    Like

  5. I’m running IE8 on XP sp3, and I get from Adobe Flash Player 10 – “Error #2000. No active Security Context”, but ONLY when I go to a Newsquest site (Local Papers/News Sites in the UK), but when I tick “Dismiss All”, it loads the page…’til I move to the next page, and the Error comes up again, stopping the pageload. Infuriating.

    Like

  6. This error sometimes fires incorrectly, if the path to an asset you are trying to load is incorrect.

    If you have a file in a folder “assets/image.jpg” and you try to load it in a web conext, but mis-type the address as, for example, “http://localhost/assssssets/image.jpg” then you get a useful error which tells you the url cannot be found.

    If, however, you are working with local files, and try to load from a relative url such as “asssssets/image.jpg”, then you get Error #2000 with no indication that the path is incorrect.

    Took me a while to figure out what the problem was. Hope this helps someone else find the issue faster.

    JcFx

    Like

Leave a comment