2 Replies Latest reply on Jun 1, 2007 1:24 PM by ForceMorph

    The ominous weird moduleloader bug - a fix!

      I'm developing a very large-scale Flex 2 app and its biggest pieces are being modularized - only make sense to do so - but I've run into the old bug of random components not working correctly, returning null reference errors for no reason, or components simply not working because they don't have parts of their class initialized. This doesn't happen to the first module initially loaded, but happens to every module loaded later. This was magnified even more when using custom components in modules. So the fix of going through everything in a module and including it in the original main app so that it would be there is far too daunting, and often I'd miss things buried deep within component classes. So I did some more research and found the basically undocumented and cryptic applicationDomain property of ModuleLoader. I added applicationDomain="{ApplicationDomain.currentDomain}" to the ModuleLoader mxml, and suddenly... every module loaded and functioned correctly. I'm still not sure exactly what it does... but my theory is that any module loaded after the first doesn't have access to the classes it's using in the main app because it's loaded into a different application domain, so it fails to function and returns errors about null references. So setting the application domain to the current one makes it stable.

      That's my theory anyway... I just wish it were documented somehow, or this bug fixed, because it's extremely frustrating.

      So far it has worked for me... not sure if it's an actual fix or just another workaround.