浏览 13473 次
锁定老帖子 主题:Flex安全沙箱解决方案
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-10
最后修改:2008-11-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 这个干吗用的? 再看看帮助 原来是用来设置运行域 和 设置是否加载安全策略文件的 当然使用方法是 var lc:.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 具体: 放一个如 getpic.asp 在服务器上 和myfalsh.swf 同一个目录 getpic.asp的代码为 <% function reReader(url) dim http set http = server.CreateObject("Microsoft.XMLHTTP") with http .Open "get", url, false, "", "" .Send reReader = .ResponseBody end with set http = nothing end function dim url url =Request.QueryString("url") response.Clear Response.ContentType = "image/gif" Response.BinaryWrite reReader(url) response.End %> myfalsh.swf 种的代码这样写 private var _loader:Loader; private var _LoadUrl:String; public function FileLoader(url:String){ _LoadUrl = url; _loader = new Loader(); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,OnLoadCompleateEvent); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,OnLoadIOErrorEvent); } //加载 public function Load():void{ var req:URLRequest = new URLRequest(_LoadUrl); _loader.load(req); } public function get content():DisplayObject{ return _loader.content; } private function OnLoadCompleateEvent(e:Event):void{ this.dispatchEvent(new Event(Event.COMPLETE)); } private function OnLoadIOErrorEvent(e:IOErrorEvent):void{ Alert.show("加载错误"); //this.dispatchEvent(new Event(IOErrorEvent.IO_ERROR)); } 调用方法 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地址 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-03-22
放在服务器上 加载 立马 报错 安全沙箱冲突 一看就天津的 呵呵~!
|
|
返回顶楼 | |