FLEX 安全沙箱问题
</cross-domain-policy>
所以这种方式有个很大弊病 就是要在对方服务器上放这么一个文件 , 别人还肯给你放啊 ? 要不就是傻了
第2种方式 很自然的就是想到用代理方法 就是 用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);
搞定?????