Reputation: 317
I have Main.fla and SkinA.fla. Both have MovieClip library item: MC_BrandLogo.
I'm loading the SkinA.swf into Main.swf in the current application domain trying to replace the class inside Main.swf. If there is no library item in the Main.fla, I can instantiate MC_BrandLogo with the correct graphic. If the MC_BrandLogo already exist in the Main.fla then that graphic is used even though I loaded new one in the current application domain.
Is there a way to replace existing linked movie clips with loaded dynamically?
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSkinLoaded);
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.load(new URLRequest("SkinA.swf"));
function onSkinLoaded(e:Event):void {
trace("loaded Skin");
addChild(new MC_BrandLogo());
}
EDITED: There is no way to override the images I was trying to override, because this is how application domains work. If the definitions exist in the parent application domain, they are used.
Upvotes: 2
Views: 1012
Reputation: 6209
As far as I know you can not overwrite a Class Definition in an ApplicationDomain unless you wish to resort to manipulating bytecode at runtime.
What you can do, however, is load your skin SWF into a child Application Domain and then retrieve the appropriate Class Definition (symbol) via ApplicationDomain.getDefinition; ie:
private var _skinAppDomain : ApplicationDomain;
function loadSkin() : void {
// Keep a reference to the Skin's application domain.
_skinAppDomain = new ApplicationDomain();
var loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext(false, _skinAppDomain);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSkinLoaded);
loader.load(new URLRequest("SkinA.swf"));
}
function onSkinLoaded(e:Event) : void {
var brandLogoSymbolName : String = "MC_BrandLogo";
// Retrieve the symbol from the Skin's Application Domain directly.
var brandLogoClipClazz : Class = _skinAppDomain.getDefinition(brandLogoSymbolName);
// Check we have the symbol.
if (brandLogoClipClazz == null) {
throw new Error("Skin SWF must include a symbol named: " + brandLogoSymbolName);
}
addChild(new brandLogoClipClazz());
}
To help debug missing symbol names in ApplicaitonDomains you can list all Class Definitions (symbols) contained by using SWF Explorer.
Upvotes: 0
Reputation: 21
Beaten to the punch. JonnyReeves is correct I believe. A good discussion on this topic can be found here:
Application Domains on Senocular
Upvotes: 2