我目前正在試驗從標準AS3應用程序和AIR應用程序中加載外部SWF文件。看起來,AIR應用程序的行爲與Flash Player運行的標準SWF的行爲方式不同。LoaderContext和ApplicationDomain隨Adobe AIR改變了嗎?
根據documentation,LoaderContext
的applicationDomain
屬性也可用於AIR應用程序,但它似乎不起作用。
我有以下代碼:
package {
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class Invoker extends Sprite
{
private var _ldr : Loader;
public function Invoker()
{
_ldr = new Loader();
_ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onChildOneComplete);
var ldrC : LoaderContext = new LoaderContext(false,
new ApplicationDomain(ApplicationDomain.currentDomain)
);
_ldr.load(new URLRequest("otherSwf.swf"), ldrC);
}
private function onChildOneComplete(e : Event) : void
{
var c1ad : ApplicationDomain = (e.target as LoaderInfo).applicationDomain;
var inad : ApplicationDomain = ApplicationDomain.currentDomain;
trace("Child One parentDomain : " + c1ad.parentDomain);
trace("Invoker parentDomain : " + inad.parentDomain);
trace("Child One has Invoker : " + c1ad.hasDefinition("Invoker"));
trace("Invoker has Invoker : " + inad.hasDefinition("Invoker"));
}
}
}
編譯此代碼爲SWF文件,並在與Flash Player推出它這樣做的輸出,這似乎是正確的:
Child One parentDomain : [object ApplicationDomain]
Invoker parentDomain : null
Child One has Invoker : true
Invoker has Invoker : true
但相同的代碼作爲AIR應用程序做不同的輸出:
Child One parentDomain : null
Invoker parentDomain : null
Child One has Invoker : false
Invoker has Invoker : true
根據文檔n,第一個輸出(使用帶有Flash Player的SWF,而不是AIR應用程序)是正確的。此外,仔細閱讀此代碼段並將應用程序域更改爲其他可能的配置(如new ApplicationDomain(null)
或ApplicationDomain.currentDomain
)確實可以顯示文檔對SWF所說的內容,但不會更改AIR應用程序的輸出。
任何線索爲什麼AIR只是忽略傳遞給加載器上下文的應用程序域?有關這個特定問題的任何文檔?
非常感謝。
請注意,您將需要通過@pigiuz – 2013-03-07 08:18:49