【发布时间】:2011-11-22 01:25:18
【问题描述】:
我遇到了一些奇怪的域间加载行为。我需要让我的加载 swf 访问跨域加载的 swf 的类和方法,但是尽管我的所有 applicationDomain 设置和跨域设置,我无法将它转换为跨域的可用类型,但它的工作原理完全相同域。
场景:
域 A 上的应用程序从域 B 加载皮肤(实际上是大型域结构的所有部分(test.domain.co.uk、assets.domain.co.uk 等),但对于 Flash 而言,它们是不同的) .目前,其中一些文件位于测试环境中,并且在上线之前将通过多个环境,因此我保持所有安全调用相对宽松。到处都是crossdomain.xml文件。
加载代码:
_skinLoader = new Loader();
addChild(_skinLoader);
var context:LoaderContext = new LoaderContext();
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
_skinLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, skinError, false, 0, true);
_skinLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, skinLoaded);
var skinurl:String = "http://www.domainB/skins/skin.swf";
var request : URLRequest = new URLRequest(skinurl);
_skinLoader.load(request, context);
COMPLETE 事件代码:
onSkinLoaded(e:Event):void{
addChild(_skinLoader);
_skin = e.currentTarget.content as ISkin;
trace("SHELL: Skin loaded:"+_skin); //======== traces out null when x-domain but traces out[object SkinObject] on the same domain or in the IDE
trace("SHELL: Skin target:"+e.currentTarget.content); //===== traces out [object SkinObject] on both
...............
}
因此,当皮肤与外壳应用程序位于同一域时,它可以工作,但当它们分开时则不行。正如您从上面的代码中可以看出的,皮肤实现了 ISkin 并扩展了抽象类 ASkin;为了处理安全问题,我将以下内容作为皮肤类的构造函数(这是 fla 的基类)。
public function SkinObject(){
Security.allowDomain(this.root.loaderInfo.loaderURL);
super();
}
其他信息:
- 皮肤构造函数类火中的跟踪
- 如果我测试
(e.currentTarget.content is ISkin),当皮肤在同一个域上时,我得到真,在不同域上时,我得到假 - 没有安全事件
- 我也尝试将加载程序上下文设置为新的 ApplicationDomain。
【问题讨论】:
标签: flash actionscript-3 cross-domain