Flex安全沙箱解决方案

开发中遇到了安全沙箱的问题,一下有几种解决方案:

1.

播放器在 8.0 以上可以使用通配符 “*” 来允许所有域:
System.security.allowDomain("*");

如果要允许多个域,可以用逗号隔开:
System.security.allowDomain("www.windshow.com", "windshow.com", "player.windshow.com");

2.关于flex跨域读取一个图片

比如 假设你的服务器事 [url=http://www.myserver.com/]www.myserver.com[/url] 而你的一个flex文件位于 [url=http://www.myserver.com/]www.myserver.com[/url] /flex/myfalsh.swf

当一个客户来访问你的这个myfalsh.swf 文件 而你的这个文件又要去 [url=http://www.otherserver.com/img/1.jpg]www.otherserver.com/img/1.jpg[/url] 这里把这个图片加载到flash中

怎么办? 最简单的方法就是 var l:loader = new loader; l.load(new urlrequest("")); 这个方式如果你的flash是直接放在本地目录上运行那还可以

放在服务器上 加载 立马 报错 安全沙箱冲突

看了看loader 的 load的方法load(request:[url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/flash/net/URLRequest.html]URLRequest[/url], context:[url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/flash/system/LoaderContext.html]LoaderContext[/url] = null):[url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/specialTypes.html#void]void[/url]

context:[url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/flash/system/LoaderContext.html]LoaderContext[/url] 这个干吗用的? 再看看帮助 原来是用来设置运行域 和 设置是否加载安全策略文件的
当然使用方法是 var lc:[url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/flash/system/LoaderContext.html]LoaderContext[/url] = new [url=http://mce_host/admin/blogs/265174/mk:@MSITStoreC\Documents%20and%20Settings\qkaibo.AIXIA\桌面\Adobe_Flex_2.0.1_Language_Reference_[Flex2.org].chm::/langref/flash/system/LoaderContext.html]LoaderContext[/url](true);
var l:loader = new loader; l.load(new urlrequest(""),lc); 这样行吗? 一样不行
还要放一个 安全策略文件 放在对方服务器的根目录下面 名称为:[b]crossdomain.xml 最好是这个名字 省得多写代码[/b]
内容为

<?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地址
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值