Compile a flex/AIR application in ANT so that the modules trim out any classes that already exist in the main SWF. Package the results into an AIR package.
Use the flex ANT tasks along with special parameters to compile your main swf and module swfs. Use the ADT command to package an AIR application in ANT.
When compiling your main swf file, use the "link-report" property to create a list of all classes linked into the main swf. When compiling the modules, use the "load-externs" property so that anything linked into the main swf isn't also included in the module swfs. Since we're compiling for AIR, make sure to use configname="air" so that the compiler uses air-config.xml and not flex-config.xml when building. To package the AIR file, you'll need to use the ant <exec> tag and call adt.bat to create the package. The example below is an example of using these techniques to build an AIR application containing two modules.
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="NitroEncryptedModulesDemo" basedir="." default="AIR">
<property name="OPTIMIZE" value="true" />
<property name="DEBUG" value="false" />
<property name="FLEX_HOME" value="C:/Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.2.0" />
<property name="src.dir" value="." />
<property name="lib.dir" value="../libs" />
<property name="out.dir" value="../bin-release" />
<property name="dbg.dir" value="../bin-debug" />
<property name="jars.dir" value="../../jars-server" />
<taskdef name="nitrolm-encrypt" classname="com.simplifiedlogic.nitrolm.LMEncryptAsset" classpath="${jars.dir}/AssetEncrypterX.jar" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="clean" description="Clean the project">
<delete dir="${out.dir}" failonerror="false" />
</target>
<target name="init" description="initialize the project" depends="clean">
<mkdir dir="${out.dir}" />
<copy todir="${out.dir}" includeemptydirs="false">
<fileset dir="${basedir}">
<exclude name="**/*.as" />
<exclude name="**/*.mxml" />
<exclude name="**/build.xml" />
<exclude name="**/*.css" />
<exclude name="**/*.properties" />
<exclude name="**/*.ser" />
<exclude name="**/*.vser" />
<include name="**/*" />
</fileset>
</copy>
</target>
<target name="compile.release" description="Compile swf modules and main swf" depends="init">
<!-- compile main SWF -->
<mxmlc file="NitroEncryptedModulesDemo.mxml" output="${out.dir}/NitroEncryptedModulesDemo.swf"
debug="${DEBUG}"
optimize="${OPTIMIZE}"
link-report="${out.dir}/report.xml"
locale="en_US"
configname="air">
<compiler.context-root>/NitroEncryptedModulesDemo</compiler.context-root>
<source-path path-element="${src.dir}" />
<library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="{locale}" />
</library-path>
<library-path dir="${lib.dir}" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
<!-- compile modules -->
<mxmlc
file="CircleModule.mxml"
output="${out.dir}/CircleModule.swf"
debug="${DEBUG}"
optimize="${OPTIMIZE}"
load-externs="${out.dir}/report.xml"
locale="en_US"
configname="air">
<compiler.context-root>/NitroEncryptedModulesDemo</compiler.context-root>
<source-path path-element="${src.dir}" />
<library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="{locale}" />
</library-path>
<library-path dir="${lib.dir}" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
<mxmlc
file="TechSupportRequest.mxml"
output="${out.dir}/TechSupportRequest.swf"
debug="${DEBUG}"
optimize="${OPTIMIZE}"
load-externs="${out.dir}/report.xml"
locale="en_US"
configname="air">
<compiler.context-root>/NitroEncryptedModulesDemo</compiler.context-root>
<source-path path-element="${src.dir}" />
<library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
<include name="*.swc" />
</library-path>
<library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="{locale}" />
</library-path>
<library-path dir="${lib.dir}" append="true">
<include name="*.swc" />
</library-path>
</mxmlc>
</target>
<target name="encrypt" description="Encrypt the various swf modules" depends="compile.release">
<nitrolm-encrypt
filename="${out.dir}/CircleModule.swf"
product="4RjPInHGpv0fFJ1CcdyG"
library="LKX_THrLWnFxAnmrKhPIjsBQ"
keydir="." />
<nitrolm-encrypt
filename="${out.dir}/TechSupportRequest.swf"
product="4RjPInHGpv0fFJ1CcdyG"
library="LKX_AOfZZCWIht7ncbIv6FQm"
keydir="." />
</target>
<target name="AIR" description="Create the AIR package for our app" depends="encrypt">
<exec executable="${FLEX_HOME}/bin/adt.bat" failonerror="true">
<arg line="-package" />
<arg line="-storetype pkcs12" />
<arg line="-keystore ${out.dir}/NitroEncryptedModulesDemo.p12" />
<arg line="-storepass 5tup1d" />
<arg line="${out.dir}/NitroEncryptedModulesDemo.air" />
<arg line="${out.dir}/NitroEncryptedModulesDemo-app.xml" />
<arg line="-C ${out.dir} NitroEncryptedModulesDemo.swf" />
<arg line="-C ${out.dir} CircleModule.swf" />
<arg line="-C ${out.dir} TechSupportRequest.swf" />
<arg line="-C ${out.dir} assets*" />
</exec>
</target>
</project>