3.12. 处理系统安全
问题
我要在应用程序中载入其他域的swf文件,并且允许它访问程序中的 ActionScript
解决办法
使用flash.system.Security.allowDomain( ), flash.system.Security.allowInsecureDomain( ),或 一个政策文件。
讨论
很多情况下应用程序有多个分布在不同域里的swf组成。如果你要载入外部域的swf文件,需要通过 flash.system.Security.allowDomain( ), flash.system.Security.allowInsecureDomain( ), 或一个政策文件设定
假设accessing.swf 在mydomain.com,它要访问otherdomain.com中的accessed.swf中的一个变量,而默认accessed.swf是不允许外部域的swf访问它,为了解决这个问题,在accessed.swf中加入以下语句:
flash.system.Security.allowDomain("http://mydomain.com");
允许指定的域可以访问它。
也许你会注意到,被载入的swf如果要访问载入它的swf是不可以的,同样,载入它的swf也要加入上面的语句设置。
域名可以是字符串形式,也可以使IP地址。如果你想让所有域都能访问它,可以设置为 "*"。 However, 但这样做可能会导致安全问题,不推荐。
如果 accessed .swf 文件在基于https://的服务器里,默认它不能被基于http://的域访问,设置flash.system.Security.allowDomain( )也没用,这时应该使用flash.system.Security.allowInsecureDomain( ) 设置非安全的http域可以访问。
这个办法虽好,但是如果经常变动域名就要重新编译swf文件就麻烦了,最好的办法是创建一个策略文件.
该策略文件是一个 XML 文件,列出了被允许的域:
<?xml version="1.0"?>
<!-- http://www.mydomain.com/crossdomain.xml -->
<cross-domain-policy>
<allow-access-from domain="www.otherdomain.com" />
<allow-access-from domain="*.adobe.com" />
<allow-access-from domain="123.45.67.89" />
</cross-domain-policy>
该文件被命名为 crossdomain.xml。通过 flash.system.Security.loadPolicyFile( )读取文件,参数为指定 crossdomain.xml 文件的URL字符串。
指定任何域都可访问:
<allow-access-from domain="*" />
阻止任何域访问:
<cross-domain-policy>
</cross-domain-policy>
分享到:
相关推荐
- `flash.system.Security.allowDomain()`:允许来自指定域名的数据加载。 - `flash.system.Security.allowInsecureDomain()`:允许加载不安全的(非HTTPS)域的数据。 此外,还需要创建并加载跨域策略文件(如`...
Security.allowDomain("*"); sound = new Sound ; sound.load(new URLRequest("醉酒歌.mp3")); schannel = sound.play(); ////////////////////////////////////////////////// lrcLoader...
allowDomain LocalConnection.allowDomain、System.security.allowDomain() allowInsecureDomain LocalConnection.allowInsecureDomain、System.security.allowInsecureDomain() and and appendChild XML....
解决这个问题的方法之一是使用`System.security.allowDomain()`或`System.security.allowInsecureDomain()`函数。这些函数可以让运行在网络沙箱中的SWF放宽对特定域的权限,从而允许加载来自该域的SWF文件。但需要...
在不同沙箱之间进行通信需要特殊处理,例如通过`flash.system.Security`类的`allowDomain()`或`allowInsecureDomain()`方法设置安全策略。 6. **处理问题的策略** 遇到安全沙箱问题时,首先需要确定代码运行的...
flash.system.Security.allowDomain("*"); flash.system.Security.allowInsecureDomain("*"); ``` **部署jPlayer** 1. 通常需要将SWF文件(如`Jplayer.swf`)和JavaScript文件(如`jquery.jplayer.min.js`)上传到...
具体做法是在Flash的ActionScript代码中导入`flash.system.Security`包,并使用`Security.allowDomain('***')`方法。这里的`'***'`应当替换为实际域名。如果你的网页要被多个不同的域访问,则可以添加多条`Security....