- Home /
Error #2070: Security sandbox violation in AIR with local file
I'm trying to load Unity content in a bigger AIR-based application using
var loaderParams:UnityLoaderParams = new UnityLoaderParams(true);
var unityContentLoader:UnityContentLoader =
new UnityContentLoader(currentAssetVO.name, this, loaderParams, false);
unityContentLoader.contentLoaderInfo
.addEventListener(Event.COMPLETE, onUnityLoaderComplete, false, 0, true);
unityContentLoader.contentLoaderInfo
.addEventListener(ProgressEvent.PROGRESS, onUnityProgress, false, 0, true);
unityContentLoader.contentLoaderInfo
.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
unityContentLoader.loadUnity();
Later when I try to do
[Bindable]
public var movieClipContainer:UIComponent;
< … snip snip … >
movieClipContainer.addChild(loader);
I get the following error:
[trace] *** Security Sandbox Violation ***
[trace] SecurityDomain 'file:///Users/username/tmp/UnityCubeMoveIntro.swf' tried to access incompatible context 'app:/MissionTesterLauncher.swf'
[Fault] exception, information=SecurityError: Error #2070: Security sandbox violation: caller file:///Users/myusernamehere/tmp/UnityCubeMoveIntro.swf cannot access Stage owned by app:/MissionTesterLauncher.swf.
at flash.display::Stage/set scaleMode()
at com.unity::UnityContent/setupStage()
at com.unity::UnityContent/onAddedToStage()
at flash.display::DisplayObjectContainer/addChildAt()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7291]
at mx.core::UIComponent/addChild()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7171]
Note that both SWF files are local, so nothing is loaded from a server. Since this is an AIR application, I can't simply use Security.allowDomain
as a quick hack.
I poked at the UnityShared.swc file and noticed this:
native public override function loadBytes(bytes:flash.utils.ByteArray,
context:flash.system.LoaderContext = null):void;
So I then tried the following:
var loaderContext:LoaderContext = new LoaderContext(false,
new ApplicationDomain(ApplicationDomain.currentDomain),
SecurityDomain.currentDomain);
loaderContext.allowCodeImport = true;
unityContentLoader.loadBytes(byteArray, loaderContext)
But this didn't work at all: i.e. the onUnityProgress
event listener never gets called and so on. Maybe the loadBytes
implementation is simply an empty stub?
How do I work around this? The AIR application is somewhat complicated and contains several different loaded SWFs, all of which have been loaded with a proper LoaderContext so they work fine, but I can't seem to get Unity content working at all.
Answer by catburton · Aug 14, 2012 at 10:45 AM
Are you using UnityContentHost from UnityShared.swc? Try referring to this example on the forums to see if you can successfully embed your unity content this way:
Yes, I'm using IUnityContentHost. The problem is not with that, but with the security context the Unity content is loaded in. The example in the thread you posted doesn't help in my case since it's still in the wrong context and currently I can't see any way to change that since loadBytes() doesn't work in UnityContentLoader.
Your answer
Follow this Question
Related Questions
Flash Export in Air application GUI events misaligned 1 Answer
Can I export a swf from Unity which is "local-with-filesystem"? 0 Answers
Exporting to Flash and Building for AIR For Mobile? 0 Answers
Find the area of the part of a game object exposed to the air in the direction of its flight 1 Answer
Creating a Self Improvement Sandbox Game 0 Answers