Peter Hall's Flash, Flex and AIR blog. News and insights into development with Flash, Flex and AIR.

This page is powered by Blogger. Isn't yours?
Sunday, October 12, 2003

excluding classes

The Flash MX 2004 compiler is very clever, in that it notices that you are using a class and will compile it into your SWF, without you having to tell it to do so. The only problem is that sometimes one class will make references to other classes in methods that you know that you aren't going to use. The compiler cannot guarantee that you aren't going to use those classes, so they always go in there. This can make your SWFs unnecessarily large. Other times, you may be using the same classes in multiple SWFs, which will be loaded into the same base movie, so you wouldn't want the classes included in both.

Luckily Macromedia have provided a solution. You can explicitly exclude classes, using a special XML file, which must be in the same directory as the FLA. The file must be named yourFlaName_exlude.xml, so if your FLA is called coolApp.fla, you would name the file coolApp_exclude.xml. Here is what the file should look like:

  <excludeAssets>
     <asset name="mx.controls.Button" />
     <asset name="mx.controls.CheckBox" />
     <asset name="mx.managers.FocusManager" />
  </excludeAssets>

This is still awkward because you will have to test pretty carefully which classes are safe to exclude and which will affect your app. For example, excluding FocusManager will not break any of the components, but it will affect the tabbing and make them look tab-focused when you click on them. The other thing to watch is that dependent classes may still be compiled, even if they are only referenced by an excluded class. This can make it a real pain to do because you have to find out which they are and also that they are not needed by some other class, that you do want.

Perhaps someone will come up with a nice set of excludes for different predefined scenarios - that would be really helpful. Or, even better, make an authoring extension, which lets you exclude classes by ticking boxes. That would be great! (anybody?)