介绍几种访问其他域swf文件的方法。
对于类似的出错信息:
SecurityError:
Error #2148: SWF 文件
file:///F:/work2010/tiger/rmpublisher.air/bin-debug/index.swf 不能访问本地资源
file:///F:/work2010/tiger/rmpublisher.air/bin-debug/plugins/plugins.xml。只有仅限于文件系统的
SWF 文件和可信的本地 SWF 文件可以访问本地资源。
at flash.net::URLStream/load()
at
flash.net::URLLoader/load()
at
com.edlt.utils::Settings/loadSettings()
解决方法:
第一种:
flex项目上点右键-->properties-->ActionscriptCompiler-->Additional
compiler arguments
加上“ -use-network=false
”,这种方式swf就无法访问网络资源了,比如socket通讯之类的。所以最好不要这样用。
第二种:
找到windows安装目录下system32/Macromed/Flash/FlashPlayerTrust,在这个目录下随便建个文本文件,在文件里输入需要访问本地资源flash的详细路径,保存。执行swf,不再出错了。OK
如:在C:/WINDOWS/system32/Macromed/Flash/FlashPlayerTrust目录下添加一个文件,比如:1.txt(文件名可任意起),文件内容为:“D:/demo/test/”即项目的路径,当然也可以设置为“D:/”。需要关闭浏览器这种设置才会生效,因为如果浏览器正在运行,Flash
player
已经读取了FlashPlayerTrust的内容,新的设置不会生效。参考http://kb2.adobe.com/cps/518/cpsid_51814.html。
第三种:
如果让一个swf可被其他域访问,使用
flash.system.Security.allowDomain(),flash.system.Security.allowInsecureDomain()。参数设置为“*”可以让所有的域能够访问它。
第四种:
使用策略文件:内容可以是ip,域名,*。
<?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"
/>
<allow-access-from domain="*"
/>
</cross-domain-policy>
再使用
flash.system.Security.loadPolicyFile() 读取这个策略文件。这种方式是最灵活,最安全的方式
浙公网安备 33010602011771号