Monday, July 23, 2007

Examining linker dependencies

To find ways to reduce SWF file sizes, you can look at the list of ActionScript classes that are linked into your SWF file.

You can generate a report of linker dependencies by setting the link-report compiler option to true. The output of this compiler option is a report that shows linker dependencies in an XML format.

The following example shows the dependencies for the ProgrammaticSkin script as it appears in the linker report:
<script name="C:\flex2sdk\frameworks\libs\framework.swc(        mx/skins/ProgrammaticSkin)" mod="1141055632000" size="5807">

<
def id="mx.skins:ProgrammaticSkin"/>
<
pre id="mx.core:IFlexDisplayObject"/>
<
pre id="mx.styles:IStyleable"/>

<
pre id="mx.managers:ILayoutClient"/>
<
pre id="flash.display:Shape"/>
<
dep id="String"/>

<
dep id="flash.geom:Matrix"/>
<
dep id="mx.core:mx_internal"/>
<
dep id="uint"/>

<
dep id="mx.core:UIComponent"/>
<
dep id="int"/>
<
dep id="Math"/>

<
dep id="Object"/>
<
dep id="Array"/>
<
dep id="mx.core:IStyleClient"/>

<
dep id="Boolean"/>
<
dep id="Number"/>
<
dep id="flash.display:Graphics"/>

</
script>



You can examine the list of prerequisites and dependencies for your application definition. You do this by searching for your application's root MXML file by its name; for example, MyApp.mxml. You might discover that you are linking in some classes inadvertently. When writing code, it is common to make a reference to a class but not actually require that class in your application. That reference causes the referenced class to be linked in, and it also links in all the classes on which the referenced class depends.

If you look through the linker report, you might find that you are linking in a class that is not needed. If you do find an unneeded class, try to identify the linker dependency that is causing the class to be linked in, and try to find a way to rewrite the code to eliminate that dependency.

The linker report

No comments: