AS3 load AS2 Aand edit(crossScripting?)
ActionScript3.0 2007/10/04 02:45首先在domain1.com放置一個由AS3編寫的main.swf
再第一影格程式碼如下
var loader3:Loader=new Loader();//載AS2 SWF
var URLrequest3:URLRequest=new URLRequest("http://domain2.com/AS2movie.swf");
loader3.contentLoaderInfo.addEventListener(Event.COMPLETE,gotit);
//loader2.load(URLrequest2, new LoaderContext(true,null,null))
loader3.load(URLrequest3);
loader3.y=200;
this.addChild(loader3);
function gotit(e:Event) {
trace("AD TYPE:"+e.target.contentType);
trace("e.target:"+e.target.content)
var w:Number=100;
var h:Number=100;
e.target.content.width=w;
e.target.content.height=h;
/*
if (e.target.contentType=="application/x-shockwave-flash" ) {
var ADP_obj:Object=new Object();
ADP_obj.w=w;
ADP_obj.h=h;
conn.send("setAD_conn", "setADProperty_fun", ADP_obj);
} else {
e.target.content.width=w;
e.target.content.height=h;
loader.visible=true;
}*/
}
var URLrequest3:URLRequest=new URLRequest("http://domain2.com/AS2movie.swf");
loader3.contentLoaderInfo.addEventListener(Event.COMPLETE,gotit);
//loader2.load(URLrequest2, new LoaderContext(true,null,null))
loader3.load(URLrequest3);
loader3.y=200;
this.addChild(loader3);
function gotit(e:Event) {
trace("AD TYPE:"+e.target.contentType);
trace("e.target:"+e.target.content)
var w:Number=100;
var h:Number=100;
e.target.content.width=w;
e.target.content.height=h;
/*
if (e.target.contentType=="application/x-shockwave-flash" ) {
var ADP_obj:Object=new Object();
ADP_obj.w=w;
ADP_obj.h=h;
conn.send("setAD_conn", "setADProperty_fun", ADP_obj);
} else {
e.target.content.width=w;
e.target.content.height=h;
loader.visible=true;
}*/
}
在domain2.com放置一個由AS2編寫的AS2movie.swf再第一影格程式碼如下
System.security.allowDomain("*");
/*
var conn:LocalConnection = new LocalConnection();
conn.allowDomain = function(sendingDomain:String) {
trace("sendingDomain:"+sendingDomain)
return true;
};
conn.Stageobj=this
conn.setADProperty_fun = function(ADP_obj:Object) {
trace("someone call me!!!")
this.Stageobj._width=ADP_obj.w
this.Stageobj._height=ADP_obj.h
};
conn.connect("setAD_conn");
*/
var conn:LocalConnection = new LocalConnection();
conn.allowDomain = function(sendingDomain:String) {
trace("sendingDomain:"+sendingDomain)
return true;
};
conn.Stageobj=this
conn.setADProperty_fun = function(ADP_obj:Object) {
trace("someone call me!!!")
this.Stageobj._width=ADP_obj.w
this.Stageobj._height=ADP_obj.h
};
conn.connect("setAD_conn");
*/
結果我收到下列的錯誤訊息
SecurityError: Error #2121: Sandbox 安全性違規:LoaderInfo.content:http://domain1.com/main.swf 無法存取 http://domain2.com/AS2movie.swf。這問題可以藉呼叫 Security.allowDomain 解決。
at flash.display::LoaderInfo/get content()
at loadpic_fla::MainTimeline/gotit()
Trackback Address :: http://diary.tw/allenliao/trackback/314

