2007. szeptember 13., csütörtök

Building monolithic Flex SWFs that still startup quickly

"...First, I created a simple plain Flex 2 Application. Next, a class called TestFactory which implements mx.core.IFlexModuleFactory was created. This class will later be used to create instances of a Module called Test. The TestFactory class also implements a public static function frame(value:Object):void which is needed later.

To link the TestFactory class onto an additional frame "outside" the default 2 frame section you'll have to add something like

  -frame test TestFactory 


to the mxmlc arguments (either in Flex Builder or on the command line). This creates the 3 frame SWF file.

At runtime when frame 3 is hit, the static frame() method on the TestFactory class is called (this is not documented anywhere) passing in an instance of the active SystemManager implementation. Inside this method you can then register the TestFactory on the ModuleManager:

ModuleManager.getModule("published://myTest").publish(new TestFactory());


Note: Although in the documentation it says to use an URL starting with publish:// it actually has to be published://. After the Module is published you can call

ModuleManager.getModule("published://myTest");


from withinh the application to get a reference to the TestFactory instance and call create() on it to create an instance of whatever is created by the factory class."

http://www.richinternet.de/blog/

0 megjegyzés: