Skip to content

Instantly share code, notes, and snippets.

@andrerocker
Created November 13, 2010 00:28
Show Gist options
  • Save andrerocker/674956 to your computer and use it in GitHub Desktop.
Save andrerocker/674956 to your computer and use it in GitHub Desktop.
Flex: Carga de modulo dinamica em Action Script 3
[Bindable]
protected var moduleInfo: IModuleInfo;
protected function menuClick(event:MenuEvent):void
{
var className:String = event.item.@data;
var executa:Function = function():void
{
var definition:Class = Class(getDefinitionByName(className));
var instance:MDIWindow = new definition();
parentDocument.mdiCanvas.windowManager.add(instance);
};
getDefinitionByNameWrapper(executa);
}
private function getDefinitionByNameWrapper(callback:Function):void
{
try {
callback.call();
}
catch(e:Error){
tryLoadModule(callback);
}
}
private function tryLoadModule(callback:Function):void
{
var postLoad:Function = function(e:Event):void { callback.call(); };
moduleInfo = ModuleManager.getModule("modules/xpto.swf");
moduleInfo.addEventListener(ModuleEvent.READY, postLoad);
moduleInfo.addEventListener(ModuleEvent.ERROR, moduleError);
moduleInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment