安全沙箱解决方案

来源:互联网 发布:地名数据库 编辑:程序博客网 时间:2024/04/29 18:10


1.
播放器在 8.0 以上可以使用通配符 “*” 来允许所有域: 
System.security.allowDomain("*");
如果要允许多个域,可以用逗号隔开: 
System.security.allowDomain("www.windshow.com", "windshow.com", "player.windshow.com");
2.关于flex跨域读取一个图片
比如  假设你的服务器事  www.myserver.com    而你的一个flex文件位于   www.myserver.com /flex/myfalsh.swf
当一个客户来访问你的这个myfalsh.swf 文件  而你的这个文件又要去 www.otherserver.com/img/1.jpg  这里把这个图片加载到flash中
怎么办? 最简单的方法就是 var l:loader = new loader; l.load(new urlrequest(""));    这个方式如果你的flash是直接放在本地目录上运行那还可以
放在服务器上  加载 立马 报错 安全沙箱冲突
看了看loader 的load的方法load(request:.chm::/langref/flash/net/URLRequest.html]URLRequest,context:.chm::/langref/flash/system/LoaderContext.html]LoaderContext =null):.chm::/langref/specialTypes.html#void]void
context:.chm::/langref/flash/system/LoaderContext.html]LoaderContext  这个干吗用的? 再看看帮助 原来是用来设置运行域 和 设置是否加载安全策略文件的 
当然使用方法是  varlc:.chm::/langref/flash/system/LoaderContext.html]LoaderContext = new.chm::/langref/flash/system/LoaderContext.html]LoaderContext(true); 
var l:loader = new loader; l.load(new urlrequest(""),lc);    这样行吗? 一样不行 
还要放一个 安全策略文件 放在对方服务器的根目录下面  名称为:crossdomain.xml 最好是这个名字 省得多写代码 
内容为
<?xml version="1.0"?> 
<?xml version="1.0"?>
 
所以这种方式有个很大弊病 就是要在对方服务器上放这么一个文件 , 别人还肯给你放啊 ? 要不就是傻了 
3.很自然的就是想到用代理方法  就是 用asp,php 等类似的程序去把这种图片读回来 然后传给flex 
FileLoader(http://www.myserver.com /flex/myfalsh.swf?url=http://www.otherserver.com/img/1.jpg);
4.BlaseDS时候使用的解决方案 
<mx:RemoteObject destination="remo" id="serviceyellow" 
        result="ResultHandleYellow(event)" endpoint="http://109.111.4.123:8080/SNUMSUNG/messagebroker/amf" > 
    </mx:RemoteObject> 
将endpoint中IP地址改为服务器的IP地址
原创粉丝点击