Flash AS3 尝试获取外部 swf 时出现安全沙箱冲突
嗨, 我正在尝试从不同的服务器将 swf 文件加载到我的 Flash 应用程序。 当我尝试在 flash IDE 上加载它(crl+enter)时,一切工作正常,但是当我将 swf 作为独立的 swf 文件运行或通过调试它时,我收到此错误:
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 文件我的服务器的根目录:
<?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”中我有:
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);
}
我真的不知道该怎么做...... 请帮忙?
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.
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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案:对于 Flash Builder 中的 Flex 4.x(当前为 4.6)和 AS3:
解决错误 # 2121 的上下文
...现在使用以下命令加载您的 SWF
Solution: for Flex 4.x (Currently 4.6) and AS3 in Flash Builder:
context to resolve Error # 2121
... now load your SWF with
在“全局安全设置”面板中添加您的工作文件夹。这允许您从文件系统中的单个 SWF 加载外部文件。如果您希望 a.swf 加载 b.swf,即使它们位于同一文件夹中,也是一样的。
这将允许您的 SWF 读取外部文件。
不过,如果您将 SWF 上传到服务器,这应该不是问题。
Add your working folder in the Global Security Settings panel. This allows you to load external files from a single SWF in your file system. Its the same if you want a.swf to load b.swf even if they is located in the same folder.
This will allow your SWF to read external files.
This should not be a problem if you upload you SWF to a server though.
您的错误来自没有跨域文件的外部位置,而不是您。查看有关使用桥接器的教程文件与外部 api 进行通信。我在这个例子中使用了 as3 和 php。诀窍是保持对您域上的跨域文件的控制。然后让您的服务器与 api 进行通信。
Your error is from the external location not having a cross domain file, not you. Check out this tutorial on using a bridge file to communicate with an external api. I used as3 and php in this example. The trick is to maintain control of the cross domain file on your domain.Then let your server communicate with the api.