I’ve read all similar topics already with no luck, so I’m posting a new question about this error.
I am trying to load a swf file from another swf file using this code:
var loader:Loader = new Loader()
//listen for loading progress
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
//listen for when the load is finished
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoaderError);
//load!
var rr:URLRequest = new URLRequest("http://localhost/Gen-Tree.swf")
loader.load(rr);
function onLoaderError(event:SecurityErrorEvent) {
trace("hi")
}
function onProgress(event:ProgressEvent):void
{
//calculate how much has been loaded
var percentageLoader:Number = event.bytesLoaded / event.bytesTotal;
//use your percentage number here to drive a loader bar graphic
}
function onComplete(event:Event):void
{
//remove listeners now that loading is done
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
//add loaded swf to the stage
addChild(loader.content);
}
and I get an error messages as follows:
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
Any ideas?
You’re trying to load the external swf off of the file system, which will throw security errors. Put it up on a server, and it should work fine, as long as both swfs are on the same domain. Or run a local server and try it on that.
If the two swfs aren’t in the same domain, you’ll need to add a
crossdomain.xml. It’ll go on the server root and it’ll look something like this:Except you shouldn’t just use
*as it’ll open you up to security risks. You’ll want to specifically white-list the other domain. You can learn more about cross domain policy files here.UPDATE:
Additionally, since the loader swf is accessing the content it is loading (through
loader.content), you’ll need to add security permissions to that content swf (looks like it is calledGen-Tress.swf):It’s also worth noting that
Loaderis aDisplayObject, meaning you can directly add it to thestagewithaddChild(loader)instead ofaddChild(loader.content). By not accessing theLoader‘s content, you can usually avoid security sandbox violation errors and not have to deal with allowing domains and cross domain policies.