如何使用 Flash (AS3) 从远程域调用 Flex SWF? [英] How do I call a Flex SWF from a remote domain using Flash (AS3)?

查看:30
本文介绍了如何使用 Flash (AS3) 从远程域调用 Flex SWF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Flex swf 托管在 http://www.a.com/a.swf.我在另一个尝试加载 SWF 的域上有一个 Flash 代码:

I have a Flex swf hosted at http://www.a.com/a.swf. I have a flash code on another doamin that tries loading the SWF:

_loader = new Loader();
var req:URLRequest = new URLRequest("http://services.nuconomy.com/n.swf");
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaderFinish);
_loader.load(req);

在 onLoaderFinish 事件中,我尝试从远程 SWF 加载类并创建它们:

On the onLoaderFinish event I try to load classes from the remote SWF and create them:

_loader.contentLoaderInfo.applicationDomain.getDefinition("someClassName") as Class

当这段代码运行时,我得到以下异常

When this code runs I get the following exception

SecurityError: Error #2119: Security sandbox violation: caller http://localhost.service:1234/flashTest/Main.swf cannot access LoaderInfo.applicationDomain owned by http://www.b.com/b.swf.
    at flash.display::LoaderInfo/get applicationDomain()
    at NuconomyLoader/onLoaderFinish()

有什么办法可以让这段代码正常工作吗?

Is there any way to get this code working?

推荐答案

这在 Adobe Flex 3 编程 ActionScript 3 PDF 第 550 页(第 27 章:Flash Player 安全性/跨脚本):

This is all described in The Adobe Flex 3 Programming ActionScript 3 PDF on page 550 (Chapter 27: Flash Player Security / Cross-scripting):

如果使用 ActionScript 3.0 编写的两个 SWF 文件来自不同的域,例如 http://siteA.com/swfA.swfhttp://siteB.com/swfB.swf—然后,默认情况下,Flash Player 不允许 swfA.swf 编写 swfB.swf 脚本,也不允许 swfB.swf 编写 swfA.swf 脚本.SWF 文件通过调用 Security.allowDomain() 向来自其他域的 SWF 文件授予权限.通过调用 Security.allowDomain("siteA.com"),swfB.swf 授予来自 siteA.com 的 SWF 文件编写脚本的权限.

If two SWF files written with ActionScript 3.0 are served from different domains—for example, http://siteA.com/swfA.swf and http://siteB.com/swfB.swf—then, by default, Flash Player does not allow swfA.swf to script swfB.swf, nor swfB.swf to script swfA.swf. A SWF file gives permission to SWF files from other domains by calling Security.allowDomain(). By calling Security.allowDomain("siteA.com"), swfB.swf gives SWF files from siteA.com permission to script it.

它更详细,包括图表和所有内容.

It goes on in some more detail, with diagrams and all.

这篇关于如何使用 Flash (AS3) 从远程域调用 Flex SWF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆