闪存AS3获得安全沙箱冲突试图获取外部SWF时,
许志国, 我特林从不同的服务器加载SWF文件到我的Flash应用程序。 当我尝试加载闪存的IDE(CRL +进入)一切工作正常,但是当我运行SWF作为一个独立的SWF文件或调试它,我得到这个错误:
Hii, I'm tring to load swf file to my flash application from a different server. When i try to load it on flash IDE (crl+enter) everything is working fine, but when i run the swf as an independent swf file or by debugging it, i'm getting this error:
SecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: file:///C|/Users/something/Desktop/blablabla/myplayer.swf cannot access http://www.somedomain.com/blablabla/lalalala/abc.swf. This may be worked around by calling Security.allowDomain.
at flash.display::LoaderInfo/get content()
at wallplayer_fla::MainTimeline/swfLoaded()[wallplayer_fla.MainTimeline::frame1:216]
Cannot display source code at this location.
我在我的服务器的根目录下的crossdomain.xml文件:
I have the crossdomain.xml file in the root of my server:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
在myplayer.swf我有:
In "myplayer.swf" I have:
Security.allowDomain("*");
Security.allowInsecureDomain("*");
...
...
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.checkPolicyFile = true;
loaderContext.allowCodeImport = true;
ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
ldr.load(new URLRequest(graySwfFilename), loaderContext);
...
...
var mcExt;
var ldr:Loader;
function swfLoaded(e:Event):void {
mcExt = MovieClip(ldr.contentLoaderInfo.content);
ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);
mcExt.x = 0;
mcExt.y = 0;
addChild(mcExt);
}
我真的不知道该怎么办? 请帮助?
I don't really know what to do... Please HELP?
解决方案:针对Flex 4.x版(目前4.6)和AS3在Flash Builder:
Solution: for Flex 4.x (Currently 4.6) and AS3 in Flash Builder:
import flash.system.SecurityDomain;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
loaderContext.securityDomain = SecurityDomain.currentDomain; // Sets the security
上下文来解决错误#2121
context to resolve Error # 2121
...现在加载的SWF
... now load your SWF with
loader.load(new URLRequest(webServerWebURL),loaderContext);