
ActionScriptで外部swfを読み込んだ時の同じClass名の扱いの件。
LoaderContextを設定するのが味噌。
actionscript3で、外部swfを読込んだ際に同じClass名があると
親swfのClassを使う。(同じドメインの場合?多分)
LoaderContextを明示的に指定してあげると別々とみなしてくれます。
private function loadSwf()
{
var req:URLRequest = new URLRequest('子.swf');
var ldr:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
//新しくドメインを設定 = Class名は別々
context.applicationDomain = new ApplicationDomain();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,init);
ldr.load(req,context);
}
ただ別々のClassとして認識するということは、
親swfのClassを子swfで使うときは少し面倒になる。
可能ならばややこしくならないように設計すべきです。
逆に親のClassを共通で使う場合はLoaderContextを以下にする。
context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
コメントを残す