Publish And Exclude: Flash CS3 Plugin for Optimizing File Size · Jul 4, 11:39 PM
Thank Matthew Tretter for hacking into existence the AS2 feature mysteriously missing from AS3. In AS2, class files could be excluded from compilation with an xml file filename_exclude.xml which listed classes to be excluded from filename.swf. I’ve modified and packaged his JSFL script into an MXP file for quick and easy installation.
Click Here to Download PublishAndExclude
Installing PublishAndExclude
The archive above includes the source, but to install only the .mxp file is needed. You must have Adobe Extension Manager installed. Simply run the extension manager and chose Install Extension… from the File menu. Then find and select the PublishAndEXCLUDE.mxp file. Now when you start up Flash CS3, a new command will appear in the Commands menu. To use the new command, the properly named _exclude.xml file should present in the same folder as the currently opened .fla file. I would also recommend assigning a shortcut key to the new command: select Keyboard Shortcuts… in the Edit menu.
The _exclude.xml File
The _exclude.xml file prevents specific classes from being compiled into the target SWF. To create your own _exclude.xml file, please study this example:
<?xml version="1.0" encoding="utf-8"?><excludeAssets><asset name="org.papervision3d.materials.BitmapFileMaterial" /><asset name="org.papervision3d.objects.parsers.Collada" /><asset name="org.papervision3d.cameras.Camera3D" /><asset name="org.papervision3d.cameras.FreeCamera3D" /><asset name="org.papervision3d.cameras.FrustumCamera3D" /><asset name="org.papervision3d.core.components.as3.utils.CoordinateTools" /><asset name="org.papervision3d.core.culling.DefaultLineCuller" /><asset name="org.papervision3d.core.culling.DefaultParticleCuller" /><asset name="org.papervision3d.core.culling.DefaultTriangleCuller" /><asset name="org.papervision3d.core.culling.FrustumTestMethod" /></excludeAssets>- Download this code: /files/code-exclude.txt
Notice that each and every class must be excluded individually. Unfortunately, wildcards are not supported.
Bonus Feature: Import XML Exclude Files into an XML Exclude File
The feature I’ve added to Matt’s original JSFL script allows you to import XML files into another XML file. Therefore, if you have several .FLA files that exclude the same classes, you can save some time spent copying and pasting. Lets say you have compiled a list of Papervision3D and GoASAP classes into two xml files named papervision3d_exclude.xml and goasap_exclude.xml. Just use the file property to exclude those classes (lines 7 & 8 below):
<?xml version="1.0" encoding="utf-8"?><excludeAssets><asset name="com.afw.ui.NavBar" /><asset name="com.afw.ui.TextScroller" /><asset file="papervision3d_exclude.xml" /><asset file="goasap_exclude.xml" /></excludeAssets>- Download this code: /files/code-exclude2.txt
When Should I Exclude Classes?
You should exclude classes from an external SWF file when those classes are already present in the loader. Obviously, if you attempted to run the external SWF alone, the Flash player would balk at the missing classes. However, if you are loading the SWF file into an SWF which already contains those classes then the loaded SWF will find the classes within the loader. Perhaps even more importantly, if another SWF containing those classes was already loaded in, then all SWFs loaded in afterwards will have access to them.
How Should I Structure my Project?
There are some disadvantages when you use externally loaded assets. Namely, that you will lose some strict typing for dynamically created objects. Therefore, you must structure your project in a way that the point of separation allows you to use as few calls to objects create like var myObject:* = new myClass() as possible. In a PureMVC project, a really great place to create this separation is inside of the view Mediators because Mediators are only supposed to contain a minimal amount of code, compared to view components (clarification: while you could theoretically clutter Mediators with view rendering code, this is frowned upon in the PureMVC Best Practices documentation [todo: link]).
Note: A detailed example will be available with the release of AFW Template for AS3.
— Pickle
Comment
Seamlessly Combining 2D and 3D in Flash with Planes, Part 1 [AS3] New AS3 Site Now Live
