我有兩個swf文件託管在不同的域aaa.com/a.swf和bbb.com/b.swf上。 a.swf正在加載b.swf並試圖將其轉換爲某個界面。當這兩個swf文件在同一個域中時,一切正常。但是,當它們位於不同的域中時,在將b.swf投射到實現的接口IComponent後,我會變爲null。這兩個swf都是使用use-network = true編譯的,並且具有相同的IComponent.as。Flash中的跨域問題
public class Wrapper extends Sprite
{
public function Wrapper()
{
super();
var request:URLRequest = new URLRequest("http://aaa.com/Component.swf");
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadingComplete);
loader.load(request,loaderContext);
addChild(loader);
}
private function onLoadingComplete(event:Event):void
{
var target:LoaderInfo = event.target as LoaderInfo;
var component:IComponent = target.content as IComponent;
component.init({"s":1});
component.run();
}
}
public class Component extends Sprite implements IComponent
{
public function Component()
{
super();
Security.allowInsecureDomain("*");
}
public function init(params:Object):void
{
//some actions
}
public function run():void
{
//some actions
}
}
我認爲包裝是A.swf中的文檔類和組件是b.swf的文檔類。是根據target.content加載的嗎?你能找出它嗎? – momo 2010-12-06 17:57:10
是的。包裝器正在加載組件,然後試圖將其轉換爲IComponent – 2010-12-08 16:24:50