Copy link to clipboard
Copied
Hi All,
I'm building an Adobe Air App for desktop and am having problems loading an external swf. Every time i try to load i get:
SecurityError: Error #2070: Security sandbox violation........ cannot access Stage owned by app....blah blah
The file that is being loaded is in a local directory, but as i understand its in a different 'sandbox' which is a security risk.
Is there any way around this?!
Any help would be much appreciated
Many Thanks
Matt
1 Correct answer
that's why i added those comments about the swf's domain. for locally loaded swfs, use:
...
SFMltd wrote:
Hi Kglad, Thanks for the Example.
if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.
The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "ca
Copy link to clipboard
Copied
you're using a loadercontext, correct? is it using currentDomain?
Copy link to clipboard
Copied
Hi Kglad,
I have tried using a loaderContext with currentDomain but I couldn't get it to work. Could you give me an example of the correct approach? Perhaps I was using it wrongly with the loader instance.
Many Thanks
Matt
Copy link to clipboard
Copied
var loaderContext=new LoaderContext(true,ApplicationDomain.currentDomain); //<-if you're loading a swf from a different domain, load policy file. ie, you need a policy file on the loaded swf's server
loaderContext.securityDomain=securityDomain.currentDomain; // " ".
var loader:Loader=new Loader();
loader.load(new URLRequest('yourswf.swf',loaderContext);
Copy link to clipboard
Copied
Hi Kglad, Thanks for the Example.
if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.
The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "cannot access Stage owned by app" error?
See below for class:
package {
import flash.display.MovieClip;
import flash.filesystem.File;
import flash.events.Event;
import flash.net.FileReference;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
public class assetPreview extends MovieClip {
private var loader:Loader;
private var mainSWF:MovieClip = new MovieClip();
public function assetPreview() {
addEventListener(Event.ADDED_TO_STAGE, initialise);
}
public function initialise(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initialise);
var allowSWF:LoaderContext = new LoaderContext(true,ApplicationDomain.currentDomain);
allowSWF.securityDomain = SecurityDomain.currentDomain;
loader = new Loader();
loader.load( new URLRequest(settingsXML.pathToSWF),allowSWF);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, viewPreview);
}
public function viewPreview(e:Event):void
{
addChild(mainSWF);
mainSWF.addChild(loader);
}
}
}
Copy link to clipboard
Copied
that's why i added those comments about the swf's domain. for locally loaded swfs, use:
SFMltd wrote:
Hi Kglad, Thanks for the Example.
if i run my class with securityDomain = SecurityDomain.currentDomain; then it throws this error: SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property.
The swf file im trying to load is stored locally so i guess this error makes sense. However if i comment out that line i get the same "cannot access Stage owned by app" error?
See below for class:
package {
import flash.display.MovieClip;
import flash.filesystem.File;
import flash.events.Event;
import flash.net.FileReference;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
public class assetPreview extends MovieClip {
private var loader:Loader;
private var mainSWF:MovieClip = new MovieClip();
public function assetPreview() {
addEventListener(Event.ADDED_TO_STAGE, initialise);
}
public function initialise(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initialise);
var allowSWF:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);
// allowSWF.securityDomain = SecurityDomain.currentDomain;
loader = new Loader();
loader.load( new URLRequest(settingsXML.pathToSWF),allowSWF);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, viewPreview);
}
public function viewPreview(e:Event):void
{
addChild(mainSWF);
mainSWF.addChild(loader);
}
}
}
Copy link to clipboard
Copied
Thanks for your help Kglad, got it working now.
Cheers
Matt
Copy link to clipboard
Copied
you're welcome.

