public function loadModule() : void
{
const info : IModuleInfo = ModuleManager.getModule( "TestModule.swf");
info.addEventListener( ModuleEvent.READY, readyHandler );
info.load(ApplicationDomain.currentDomain);
}
private function readyHandler( event : ModuleEvent ) : void
{
trace( event.type );
}
Whenever I invoked the
loadModule()
function at the application creation complete, no trace would appear in my console. WT(bleep). Kept looking at the code, and re-launching the application, assuming that this time it will do it (come on, you've done that too, knowing perfectly well that the outcome will be the same ;-) After a dozen time (yes, I'm that stupid) and blaming the new Flash Player 10, I decided to read the documentation, and came across this:"Be sure to define the module instance outside of a function, so that it is not in the function's local scope. Otherwise, the object might be garbage collected and the associated event listeners might never be invoked."
Retard !!!
Readjusted the code, as follows:
private var m_info : IModuleInfo;
public function loadModule() : void
{
m_info = ModuleManager.getModule( "TestModule.swf");
m_info.addEventListener( ModuleEvent.READY, readyHandler );
m_info.load(ApplicationDomain.currentDomain);
}
And guess what ? it works! After more reading, found out that the former code was a great way to pre-load modules. Anyway, hope you find this useful and funny. And remember: When all fails, RTFM. Or should it just be RTFM - LOL!
3 comments:
Thank you!
This was killing me for days!
I had to actually deploy the version of my application without modules, because I couldn't figure out why the firt time the module randomly will not launch. Next time, I will have to read the documentation. :-)
Very nice article..
You save my day :) Thank you for sharing..
Thank you so much! Almost pulled all my hair out trying to figure it out.
Post a Comment