Flash AS3 尝试获取外部 swf 时出现安全沙箱冲突

发布于 2024-10-30 21:32:15 字数 1589 浏览 6 评论 0原文

嗨, 我正在尝试从不同的服务器将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与风相奔跑 2024-11-06 21:32:15

解决方案:对于 Flash Builder 中的 Flex 4.x(当前为 4.6)和 AS3:

    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 的上下文

...现在使用以下命令加载您的 SWF

loader.load(new URLRequest(webServerWebURL),loaderContext);

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 

context to resolve Error # 2121

... now load your SWF with

loader.load(new URLRequest(webServerWebURL),loaderContext);
不知所踪 2024-11-06 21:32:15

在“全局安全设置”面板中添加您的工作文件夹。这允许您从文件系统中的单个 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.

时光沙漏 2024-11-06 21:32:15

您的错误来自没有跨域文件的外部位置,而不是您。查看有关使用桥接器的教程文件与外部 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文