PDA

View Full Version : File sizes annoying. What am I doing wrong?


charlesshoults
06-23-2009, 09:02 PM
What sort of sense does Flex make when it builds the swf files at compile-time? In my first experience building a project with Flex (no experience in Flash), I started out writing the entire thing as one file. I then learned to use external classes and externalize code into actionscript files. The file size was obviously enormous and just the act of writing code began to crawl. I then started using modules and external applications loaded through the SWFLoader. File sizes came down some, but not much.

At present, I have disabled most of my application and am working with just three swfs. My main mxml file loads the other two swf files as modules that are not optimized against the main application. Here's the trick. One of the functions of my main file was to set up a timer to fire off every 60 seconds, update two datagrids and a tree. I moved this code out of the main file and into one of the modules, reducing the main file by about 100 lines and removing the timer, URLLoader and ResultEvent. But when I exported a release build, the main swf actually increased by 16kb.

What the heck?

mattb
06-23-2009, 09:39 PM
Unfortunately Flex SWFs can be pretty big, usually due to the Flex framework being compiled in there somewhere. It's a guess but by moving stuff out to a module, you would have to add code (and possibly extra classes) to handle loading the module which may have made the SWF bigger.

charlesshoults
06-24-2009, 12:57 AM
Wow, yeah. Overhead is nasty stuff. As it turns out, if I load the modules using this:
<mx:ModuleLoader url="siteContainer.swf" id="devel"/>
My file size is 264kb. However, if I use this:
public function openBase():void { modTgt = "interfaceContainer.swf"; loadContainer() }
public function loadContainer():void {
moduleInfo = ModuleManager.getModule(modTgt);
moduleInfo.addEventListener(ModuleEvent.READY, renderContainer);
// moduleInfo.addEventListener(ModuleEvent.PROGRESS, showProgress);
moduleInfo.load();
}
public function renderContainer(event:ModuleEvent):void {
switch(modTgt) {
case "interfaceContainer.swf" : interfaceBox = moduleInfo.factory.create() as interfaceContainer;
interfaceBox.y = 0; interfaceBox.x = 0;
baseCanvas.addChild(interfaceBox); break;
}
}
The includes needed to get it to work (ModuleEvent, IModuleInfo and ModuleManager) add another 400kb.

Peter Cowling
06-24-2009, 09:15 AM
I would recommend taking a look into a couple of compiler options (http://livedocs.adobe.com/flex/3/html/help.html?content=modular_4.html) that aim to reduce link/externs redudancies between the main application and modules.

This will not alleviate the specific problem that you note below, but should help reduce the overall footprint.

charlesshoults
06-24-2009, 10:18 PM
I figured out the ModuleManager issue. I had been using the longer method because I hadn't figured out how to communicate from module to module while only using the single line to load the module. I've now realized that the reference basically works as parentApplication.interfaceMod.child.characterMod. child.avatarMod.child.importTool.visible=true;

References work now, and I've cut about 2MB out of my project as a whole. My main swf is down to 196kb.