Saturday, July 28, 2007

Flex - Generate a ModuleLoader at Runtime

I spent most of a day running up against a problem in Adobe's Flex 2.0. Flex 2.0.1 introduced the concept of modules. With this, you can stick a <mx:ModuleLoader> component in your .mxml file, then load it with the url to your module .swf file when you need it.

Now, I wanted to allow the user to load arbitrary modules at arbitrary times, and then load those into a ViewStack component. The problem is, no matter what I did, I couldn't seem to get the dynamically loaded module to obey sizing (IE, height="100%"). Here's the solution: You have to put the ModuleLoader in a Canvas, and then add the Canvas to your ViewStack. Also, you must use percentWidth and percentHeight in your <Module> tag (not width and height).

1 comment:

Anonymous said...

Dude, seriously, you're supposed to be keeping me awake for this thing.. SNORE.