SWF SecurityError: Error #2000: No active security

2019-01-20 03:50发布

问题:

Hi I have a flash image gallery that worked just fine, until few days a go it stopped loading the images. the debugger throws this error :

SecurityError: Error #2000: No active security context.

can someone explain what can be the cause?

回答1:

Did your images extensions change, possibly from like .jpg to .JPG or something?

Typically this is called if there is a problem with your external media. Here's a workaround for it, but I typically try and solve versus make it go away.

setTimeout( function():void{fileReference.load();}, 1);

Hope this helps.



回答2:

I've run into this problem when working with loading images where the path is located in an external XML file. So... I load the XML get the path from it but then the problem I had was I was loading 30+ images and the error was popping up only 6 times so.. I had no idea which file locations where the bad ones.

If you want flash to out put more info than just :

SecurityError: Error #2000: No active security context.

Add this event listener to your Loader:

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

and finally this function:

protected function ioErrorHandler(e:IOErrorEvent):void{
    trace(e.text);
}

With this in place your Security Error will convert to a URL Not Found Error with the file location you supplied. With this information in hand it should be easier for you to debug the problem.

Error #2035: URL Not Found. URL: file:////Volumes/Macintosh%20HD/Users/cleanshooter/Documents/Website%20/here/there/everywhere/30805/filename.jpg


回答3:

I faced this issue before,the final conclusion was related to incorrect image path or name



回答4:

I ran across this issue and used the above setTimeout example but for a slightly different purpose. I was calling a php script that hit Twitter and got the same security issue in Flash debug player. I just wanted to add my example which builds on the above to show how you can use this "workaround" for URLLoader as well as fileReference.

var myXMLLoader:URLLoader = new URLLoader(); 

var urlStr:String = "http://www.yourdomain.com/php/twitter.php"; 
var myVariables:URLVariables = new URLVariables();
myVariables.twitterID = "yourtwitterID";

var myURLRequest:URLRequest = new URLRequest(urlStr)
myURLRequest.data = myVariables;

setTimeout(function():void {  myXMLLoader.load( myURLRequest ); }, 1);

myXMLLoader.addEventListener(Event.COMPLETE, onXMLLoadHandler);


回答5:

You need to handle the error:

loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPError);
protected function onHTTPError(e:HTTPStatusEvent):void{
     trace("HTTPError"+e.status);
}

This way it will handle the error and works fine.



回答6:

In response to headwinds:


In AS3 you need to import flash.utils.setTimeout. The syntax for setTimeout is setTimeout(A, B, ...rest);

Where B is the function to get called afterwards, A is the delay in ms (e.g. 1000 for a second) and C is any number of parameters you need to provide for the function, separated by a comma.

E.g.

import flash.utils.setTimeout;
// package, etc
//main function
setTimeout(respond, 500, true, false);
private function respond(A : Boolean, B : Boolean) : void {
   var result : Boolean = A == B;
   trace(result);
}