In Loki We Trust The many projects of Lokkju, Inc


Supporting dynamic FlexFileSets in Flex’s compc and mxmlc Ant tasks

If you are using the mxmlc and compc tasks in Ant to compile flex code, there is no documented way to make the fileset-like children accept a dynamic include pattern - that is, one you set based on conditionals.

In my case, I need to have a list of included libraries in my, and only include those ones in my compc task. The solution is to use patternsets and a custom ant macro. See the source below, but essentially you do the following:

  1. Create a new patternset, assigning it an id
  2. Use the macro to add a new patternset for each pattern in your list of library patterns (as defined in you, or dynamically, or...)
  3. assign that patternset to the library-path of compc

Important: All the patterns must decend from the same root directory as set in the library-path. If you need multiple root directories, you must use multiple library-path directives and multiple patternset refids.


<?xml version="1.0" encoding="utf-8"?>
<project name="My Component Builder" basedir=".">
  <taskdef resource="flexTasks.tasks" classpath="${basedir}/flexTasks/lib/flexTasks.jar" />
  <property file=""/>
  <property name="FLEX_HOME" value="C:/flex/sdk"/>
  <property name="DEPLOY_DIR" value="c:/jrun4/servers/default/default-war"/>
  <property name="COMPONENT_ROOT" value="components"/>
  <macrodef name="">
    <attribute name="patternset"/>
    <element name="nested" optional="yes" implicit="true"/>
      <patternset id="tmp">
        <patternset refid="@{patternset}"/>
      <patternset id="@{patternset}"><patternset refid="tmp"/></patternset>
      <patternset id="tmp"/>
  <patternset id="compc.library-path" />
  <for list="${compc.libraries}" param="lib">
      < patternset="compc.library-path">
          <include name="@{lib}" />
  <target name="main">
      include-classes="custom.MyButton custom.MyLabel">
      <source-path path-element="${basedir}/components"/>
      <include-file name="f1-1.jpg" path="assets/images/f1-1.jpg"/>
      <include-file name="main.css" path="assets/css/main.css"/>
      <library-path append="true" dir="${compc.libdir}">
        <patternset refid="compc.library-path" />
  <target name="clean">
      <fileset dir="${DEPLOY_DIR}" includes="MyComps.swc"/>

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment


No trackbacks yet.