I have a Button that when clicked loads a Flex module in my AIR application. However, occasionally the Module fails to load the first time the button is clicked, but it works the second time it’s clicked. When I debug it in the debugger the READY event is not fired so the remaining logic is never called.
var moduleInfo:IModuleInfo = ModuleManager.getModule(managedModule.url);
moduleInfo.addEventListener(ModuleEvent.READY, function(event:ModuleEvent):void {
trace("ModuleEvent.READY called.");
});
moduleInfo.addEventListener(ModuleEvent.ERROR, function(event:ModuleEvent):void {
trace("ModuleEvent.ERROR called.");
});
moduleInfo.addEventListener(ModuleEvent.SETUP, function(event:ModuleEvent):void {
trace("ModuleEvent.SETUP called.");
});
moduleInfo.addEventListener(ModuleEvent.PROGRESS, function(event:ModuleEvent):void {
trace("ModuleEvent.PROGRESS called.");
});
moduleInfo.addEventListener(ModuleEvent.UNLOAD, function(event:ModuleEvent):void {
trace("ModuleEvent.UNLOAD called.");
});
moduleInfo.load(ApplicationDomain.currentDomain);
The ApplicationDomain.currentDomain is needed to fix other issues, but having it there or removing it doesn’t seem to make a difference. Sometimes the modules just doesn’t load. The output is roughly as follows:
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[SWF] MyStupidModule.swf – 342,932 bytes after decompression
[trace] ModuleEvent.SETUP called.
[trace] ModuleEvent.PROGRESS called.
Notice READY is never called, and neither is ERROR. If I click the button again here is what is printed out:
[trace] ModuleEvent.SETUP called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.READY called.
Any clues what could be causing this? We are using Flex 3.6.0 AIR 2.6.019
Store reference somewhere in the owner class to the ModuleInfoProxy (IModuleInfo) – the instance that ModuleManager.getModule() returns for you, for example
ModuleInfoProxy uses weak reference events and GC can remove it completely with event handlers if the object has no more reference to it. Storing a reference to IModuleInfo in a local variable makes that object eligible for GC once the load() method exits. If that happens before the module has fully loaded your listeners wouldn’t be called back.