Flex4 ModuleLoader and Runtime Skins

Recently I’ve been trying to load a Module into a basic flex application and I hit a roadblock when dispalying them into the UI. Even though the styles were loaded correctly, the modules didn’t look properly.

Narrowing down the problem I realized that the difference is made by the code below:

var moduleLoader : ModuleLoader = new ModuleLoader();
moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
addElement( moduleLoader );
moduleLoader.loadModule( "MyModule.swf" );


var moduleLoader2 : ModuleLoader = new ModuleLoader();
moduleLoader2.applicationDomain = ApplicationDomain.currentDomain;
moduleLoader2.addEventListener( ModuleEvent.READY , moduleLoader_readyHandler );
moduleLoader2.loadModule( "MyModule.swf" );
protected function moduleLoader_readyHandler( event : ModuleEvent ) : void
     addElement( IVisualElement( ModuleLoader( event.currentTarget ) ) );

In this last code, I wait until the module gets properly loaded and then I’m adding it to the display list.

In the first code, I’m adding the moduleLoader form the start, even before calling its load method.

The first code example is the one that works, and the last code example it doesn’t work. I don’t know how to explain this behavior, but according to my tests, if you add the moduleLoader to the display list, before loading the module itself, the styles are applied correctly. Otherwise, the loaded modules won’t have them applied.

Loading modules at runtime it’s a powerful feature, and at the same time, you have to use it carefully because it can lead to memory leaks. This post describes more about what the issues are, and how to avoid them.


Sorry, the comment form is closed at this time.

Comments RSS Feed