Skip to content


Before I Knew About Flex Libraries

I wanted to find a way to make my ActionScript library files into a SWC file for easy distribution. There are definitely ways to go about it, but I wanted to find a way that wouldn’t open a Pandora’s box of workarounds, learning curves, and bullshit. So, time for research.

First, I found the rather insane way of going about it by manually writing every single import statement into a document class. In this guy’s defense he is only doing one class and he is making a MXP out of it, so it’s different than what I was looking for.

I’ve heard about ANT tasks, now that I am a Eclipse and Flex user. So, I did some research on this and it seemed closer to what I was looking for. I found one or two places with some stuff to get me started. So I modified this one. After the learning curve blues, I got it to work, minus compiler warnings and a problem with the Vector class not in the Flex 3 SDK. It’s cool that ANT build files are XML so it feels familiar, but it’s a whole world to learn about.

Little did I know there was an answer closer to home. This is exactly what Flex Libraries are for. Built right into Flex. So simple, I should of looked into this first before going into new programming avenues. The one thing I don’t like about the Flex Library is that the SWC file takes the name of the project. There doesn’t seem to be any way to change it, I looked until late into the night for a renaming answer. So advantage ANT task on that. Also the Flex Library makes the SWC a derived file, and that doesn’t sync with my SVN repository. So, for now I am going with the Flex Library until I obtain the strength of an ANT. Here is the ANT task that I put together for what’s it worth.

<!--build.xml -->
<project name="AS3Library" basedir="." default="swc">
 
	<!-- load user configuration properties -->
	<property file="build.properties" />
	<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
 
	<!-- create swc file base on config -->
	<target name="swc">
		<fileset id="sources" dir="${basedir}${input}">
			<include name="**/*.as"/>
		</fileset>
		<pathconvert property="classes" pathsep=" " refid="sources">
			<chainedmapper>
				<globmapper from="${basedir}${input}/*" to="*"/>
				<mapper type="package" from="*.as" to="*"/>
			</chainedmapper>
		</pathconvert>
		<echo message="compiling classes ${classes}"/>
		<compc output="${output}/${swc}.swc" include-classes="${classes}">
			<source-path path-element="${basedir}${input}"/>
		</compc>
	</target>
 
</project>
#build.properties
 
# location of flex sdk
FLEX_HOME = /Applications/Adobe Flex Builder 3 Plug-in/sdks/3.2.0
 
# input location, can be blank of single dir with leading slash 
input =
 
# output folder, doesn't need slash
 
output = .
 
# name of the swc exported
swc = as3library

Posted in ActionScript 3.0, Eclipse, Flex, Work. Tagged with , , , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.