表現:
使用ModuleManager去加載一個Module的時候, 所有的事件都激發不了.
代碼:
- var testModule:IModuleInfo = ModuleManager.getModule('modules/pub/User.swf');
- testModule.addEventListener(ModuleEvent.READY,onModuleReady);
- testModule.addEventListener(ModuleEvent.SETUP, onModuleSetup);
- testModule.addEventListener(ModuleEvent.PROGRESS,onModuleLoading);
- testModule.load();
打個賭, ModuleEvent里所有的事件都不會被激發.
原因:
在addEventListener之后, testModule的Event Listeners就可能被GC了.
解決:
不要聲明局部IModuleInfo對象.
相關鏈接:
http://bugs.adobe.com/jira/browse/SDK-14021
https://bugs.adobe.com/jira/browse/SDK-11389
"References to IModuleInfo must be maintained to keep the event listeneres alive. If the IModuleInfo is defined in function local scope the event listeners may get garbage collected. "