Sharing the Code

Programming stuff that might be useful to others

Packaging a class library into a SWC in Flash

You can package Actionscript classes into a SWC files – they are equivalent to JAR files in Java. You then reference the SWC file from your FLA. You might want to do this if you come up against the memory limit in the Flash compiler, or you might want to distribute libraries without distributing the source code. It also speeds up compiling because you are including pre-compiled code. The following instructions are for CS4 but it works in CS3 also. Thanks to Lu for coming up with this – he has more details on this in his blog.

1. Create a FLA and within it create a dummy MovieClip – for example a rectangle
2. You will need to create a class that references all the classes in your library, e.g.:

[sourcecode language=’java’]
package com.markhorgan.library {
import flash.display.MovieClip;
public class Package extends MovieClip {
var a:Array = [Class1, Class2];

3. Right-click on your dummy sumbol in the library and select Properties
4. Check Export for Actionscript in the Linkage section and set the Class field to the full class name of the class you’ve just created like the one above e.g. com.markhorgan.library.Package, and press OK
5. Right-click on the sumbol again and select Component Definition… and set the Class field the same as in step 4, and press OK
6. Right-click on the symbol again and select Export SWC File… and give a name to the SWC file.
7. You can use the SWC file in another FLA by going to File > Publish Settings > Flash Tab and Settings button next to the script version. There click on the Library Path tab and add the path to the swc e.g. ../lib/library.swc

Comments are closed