Ant task to generate SWC and ASDOC for a library.
First create a property file to store location of your sdk and other information regarding your application: asdoc.properties - set properties file;
###################################################################
# Author: Elad Elrom - creates ASDOC and SWC
###################################################################
# Location of sdks directories
sdk.home = /Users/user/Applications/Adobe\ Flex\ Builder\ 3\ Plug-in/sdks
# Location of sdk version
sdk.dir = ${sdk.home}/3.2.0
# Location of asdoc.exe
asdoc.exe = ${sdk.dir}/bin/asdoc
# ASDOC information
src.dir = /Users/user/Documents/workspace/Library
doc.dir = /Users/user/Documents/workspace/Library
doc.src = ${doc.dir}/src/com/elad/API
output.dir = ${doc.dir}/asdoc
# Libpath location to be included
libpath = ${doc.dir}/libs
# file name and folder
swc.dir = /Users/user/Documents/workspace/Library/swc
swcfilename = library.swc
FLEX_HOME = ${sdk.dir}
# ASDOC title for html pages
main.title = ASDOC Title
window.title = ASDOC Title
</p>
Next, create the ant task to generate the asdoc and SWC file. Notice that I placed the flexTasks.jar in my local library, but feel free to point to it directly.
<project name="ASDoc build" default="main" >
<!-- make sure that flexTasks.jar which is located in skd/ant/lib/flexTasks.jar otherwise you'll get an error message -->
<taskdef resource="flexTasks.tasks" classpath="libs/flexTasks.jar" />
<!-- defines all values for the ASDoc compiler -->
<property file="asdoc.properties" />
<!-- main target: cleans and compiles ASDocs -->
<target name="main" depends="clean-asdoc-directory, create-docs, clean-swc-directory, swc-generator" />
<!-- deletes and recreates the asdoc directory -->
<target name="clean-asdoc-directory" >
<delete dir="${output.dir}" />
<mkdir dir="${output.dir}" />
</target>
<!-- deletes and recreates the swc directory -->
<target name="clean-swc-directory" >
<delete dir="${swc.dir}" />
<mkdir dir="${swc.dir}" />
</target>
<!-- runs the asdoc.exe compiler on the source -->
<target name="create-docs" >
<exec executable="${asdoc.exe}" failonerror="true" >
<arg line="-external-library-path='${libpath}/'" />
<arg line="-doc-sources ${doc.src}" />
<arg line="-output ${output.dir}" />
</exec>
<echo>ASDOC created successfully</echo>
</target>
<!-- generate the swc -->
<target name="swc-generator" description="Compile the SWC file">
<compc output="${swc.dir}/${swcfilename}">
<include-libraries file="${libpath}/" />
<!-- include our Class packages into the build (com folder) -->
<include-sources dir="${doc.dir}/src/com" includes="*" />
</compc>
<echo>SWC created successfully</echo>
</target>
</project>
</p>






















the swc task argument include-sources is pretty limited, it does not allow you to perform any tweaking on the source (in fact, it didn’t exist in Flex 2 at all, I don’t think). I use an ant fileset routine to move through the soruce directory and ignore files by name or regexp, and then create a list of classes for the include-classes task argument. This approach is messier, but ends up being the only option if you have a project that compc chokes on.
Use optimize and debug false to reduce swc size.