Flash AS3 在尝试获取外部 swf 时出现安全沙箱违规 [英] Flash AS3 Getting Security sandbox violation when trying fetch an external swf
问题描述
我正在尝试将 swf 文件从不同的服务器加载到我的 Flash 应用程序中.当我尝试在 Flash IDE (crl+enter) 上加载它时,一切正常,但是当我将 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?
推荐答案
解决方案:针对 Flash Builder 中的 Flex 4.x(当前为 4.6)和 AS3:
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
... 现在用
loader.load(new URLRequest(webServerWebURL),loaderContext);
这篇关于Flash AS3 在尝试获取外部 swf 时出现安全沙箱违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!