/customers/iconara.net/iconara.net/httpd.www/blog/wp-content/plugins/wp-super-cache/wp-cache-phase1.php Iconara » Flex Compiler API

Flex Compiler API

This is really great: Flex Doc Team: Java-based Compiler API. It’s the Flex compiler exposed as a Java API, which means that finally someone (perhaps I) can write a set of proper Ant tasks for Flex.

For some time I have used a set of macrodefs to compile my Flex applications, because the Ant tasks provided by Adobe aren’t very good. They don’t integrate easily with Ant, so to do some things becomes really tricky. Before writing my macrodefs I entertained the thought of writing Java-based tasks that wrapped the flex2.tools.Compiler class. However, that didn’t work out very good since that class wasn’t really made to be used in other ways than from the command line. Trying to wrap it was more work than I was interested in.

Now it seems like this has changed. I don’t know how long the compiler API has been around, but it can’t be that long (there aren’t very many references out there), but now it’s definitely time to write those Ant tasks.

My macrodef-based compc task lets me do this (it’s called swcc as not to clas with the compc task, should I want to use them both in the same build file for some reason):

<target name="dist-utils">
  <swcc source-path="${src.home}" output="${dist.home}/utils.swc">
      <fileset dir="${src.home}">
        <include name="net/iconara/util/"/>
        <exclude name="/Test"/>
      <fileset dir="${dist.home}" includes=".swc"/>
      <fileset dir="${lib.home}" includes=".swc"/>

i.e. specify which classes I want to include in the .swc based on a file glob, plus specify exclusions and whatnot. It’s fully integrated with Ant, and arguments like include-path (which I call libraries) take filesets, they aren’t filesets themselves, which makes things so much easier when you want to do more complex build scripts.

I’m going to read though the PDF that came with the Flex Compiler API and see what’s possible, but so far, having only glanced through it, I’m quite happy with what I’ve seen.

2 Responses to “Flex Compiler API”

  1. Erki Esken Says:

    Have you tried Antennae Ant scripts for Flex compiler?

  2. Theo Says:

    Yes, I have. I don’t use it for two reasons: my macrodefs (which I wrote before I heard of Antennae) do more or less everything that Antennae does, and Antennae seems to me (and I may be wrong here, it was some time since I looked at the project) to be an all-or-nothing deal: use Antennaes build files and it will work nicely, but you have to adhere to their idea of how to do things, or at least you need it all to be able to run their mxmlc, because it depends on a the rest. As I said, I might be wrong on that last point, and I assume a lot of people find it useful.

    My problem hasn’t been that I couldn’t use Ant to build my Flex applications, but that writing tasks using macrodefs is quite tricky, to do more advanced things a real programming language helps a lot. So far I haven’t felt that the effort was worth it, because in the end I still would have to build a command string to pass off to exec, a hackish solution at best. Now I it seems I can do it much cleaner and simpler, and at the same time be able to do some more advanced things.

Leave a Reply