views:

242

answers:

3

Here's a dumb question. I compile my Flex application with several swc's (libraries) and it creates a swf file. The sum of the swc's is roughly 4 MB yet the actual swf generated is only 1.6 MB. How is this possible?

Thanks!

+5  A: 

The compiler only compile classes from the swc that your application need, unless you specify which classes you want to 'embed'. Hence the smaller size of the swf at the end.

PeZ
+1  A: 

To expand on PeZ's response a bit, typically SWCs supplied to the Flex application compiler using the "library-path" compiler argument:

library-path path-element [...]

Links SWC files to the resulting application SWF file. The compiler only links in those classes for the SWC file that are required. You can specify a directory or individual SWC files.

You can use "include-libraries" instead:

include-libraries library [...]

Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used.

Contrast this option with the library-path option that includes only those classes that are referenced at compile time.

You'll typically want to use "library-path" to help keep the size of your SWF as small as possible. However you may need to use "include-libraries" if your application instantiates classes from a SWC via reflection only. Since these classes are not actually linked to in the application, they won't be included if you use "library-path" to reference the SWC, and you'll get a runtime error during instantiation since the type is not available. However if you use "include-libraries" the class (and all other classes in the SWC) will be available to the app.

cliff.meyers
A: 

1) in swf file only required classes are included
2) more files result in additional header information that will also increase size slightly.
To reduce the size of flex swf you can use these techniques mentioned in this article :
http://askmeflash.com/article_m.php?p=article&id=9

Sydney