“SecurityError: Error #2000: No active security context.”

Uncategorized


I encountered a strange bug in Flash player 10 today. A simple flash animation, scripted in AS3, which gave no errors inside the CS3 IDE threw the following error when run inside the browser (which was running flash player 10):

SecurityError: Error #2000: No active security context.

Now, the animation itself is completely static, no external content or links of any kind, so this error threw me off. A quick google search later, and I had tracked the bug down the the following innocuous line of code:

setTimeout(_launchTimer.start, 3000);

“_launchTimer” being a simple Timer object. The workaround, was to wrap the call to the timer’s start() function in an anonymous function, like so:

setTimeout(function():void{_launchTimer.start();}, 3000);

Very strange indeed… It seems like FP10 doesn’t like setTimout calling functions that aren’t in the same scope from where the setTimeout is being called for some reason. I’m blogging about this so that hopefully, other developers tearing their hair out at this strange bug might be helped by this.
Also, happy 2009 everybody!

Gravatar

-Gilles Vandenoostende

Hi, I’m the site’s owner. If you like my articles, maybe you ought to follow me on twitter. Just sayin’.

One Comment

The same error sometimes happens for loading data using the filereference.load method. the data property of the filereference contains the error message and not a byte array as expected.

In this case, I used your solution and wrapped the load function in a similar way, which is a little bit :

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

Maybe there are some more elegant ways to achieve this, however it works for me.

Posted by Ingo at May 20th, 2009 at 2:57 am.

Leave a Comment