Wednesday, 30 September 2009

Flex Manifest Files (with Flex ant)

All of the Flex framework components are mapped to a single namespace, this means that you are only required to use one import in MXML to use any framework component (xmlns:mx=""). The main advantage of this is a short list of imports, but it also means that the underlying package structure could change without needing to recompile your MXML classes.  Note that Actionscript classes always require the full package name when imported.  The following snippet provides an example of how the single namespace will appear even though the three components are in different packages:
   <custom:MyComponent />
   <custom:MyContainer />
   <custom:MyAsset />
It is actually possible to do the same for your own libraries, by using a manifest file. A manifest file is specified when compiling your library, and it provides a mapping between a single namespace and a list of fully qualified class names.  Your library must be included as a SWC in Flex Builder in order for the single namespace to be picked up, it will not work if the library is included as a project.  Auto-complete will work in Flex Builder providing the library is included in this way.  Although a new namespace is specified, the old namespace can still be used, this makes introducing a single namespace backwards compatible.

There are two steps to compiling your library in this way, the first is creating a manifest file. This is a simple XML file like the one below, which specifies mappings between the fully qualified class name and the new tag for the class:
<?xml version="1.0" encoding="UTF-8" ?>
   <component id="MyComponent" class="com.benlondon.component.MyComponent"/>
   <component id="MyContainer" class="com.benlondon.container.MyContainer"/>
   <component id="MyAsset" class="com.benlondon.asset.MyAsset"/>
The second step is to specify the new namespace and manifest file to the compc compiler. In this example the compiler arguments would be:
-namespace http://custom.namespace manifest.xml
-include-namespaces http://custom.namespace
The Flex ant compc task requires configuration as follows:
<compc ...
   <namespace uri="http://custom.namespace" manifest="manifest.xml" />
Once you have built your library as specified above, users of your library are ready to start using a single namespace. Flex Builder seems to choose the namespace prefix (in my example "custom") as the first part of a URL chosen as a namespace.


  1. 2 years later, and this is still relevant! This helped. Rock on!

  2. This just saved me a huge amount of time and got our build up and running again. Thanks!

  3. This is imperative and it is likewise present in both self-awareness and manifestation that exclusive considering the objective won't take you to the objective rather you need to work your way towards your objective by putting some genuine exertion.Instant manifestation technique