Adobe Flex 3 Help

Compiling components using namespaces

When you have many components in one or more packages that you want to add to a SWC file and want to reference from an MXML file through a custom namespace, you can list them in a manifest file, then reference that manifest file on the command line. Also, you can specify a namespace for that component or define multiple manifest files and, therefore, specify multiple namespaces to compile into a single SWC file.

When you use manifest files to define the components in your SWC file, you specify the namespace that the components use in your Flex applications. You can compile all the components from one or more packages into a single SWC file. If you have more than one package, you can set it up so that all packages use a single namespace or so that each package has an individual namespace.

Components in a single namespace

In the manifest file, you define which components are in a namespace. The following sample manifest file defines two components to be included in the namespace:

<?xml version="1.0"?>
<!-- SimpleManifest.xml -->
<componentPackage>
    <component id="MyButton" class="MyButton"/>
    <component id="MyOtherButton" class="MyOtherButton"/>
</componentPackage>

The manifest file can contain references to any number of components in a namespace. The class option is the full class name (including package) of the class. The id property is optional, but you can use it to define the MXML tag interface that you use in your Flex applications. If the compiler cannot find one or more files listed in the manifest, it throws an error. For more information on using manifest files, see About manifest files.

On the command line, you define the namespace with the namespace option; for example:

-namespace http://mynamespace SimpleManifest.xml

Next, you target the defined namespace for inclusion in the SWC file with the include-namespaces option; for example:

-include-namespaces http://mynamespace

The namespace option matches a namespace (such as "http://www.adobe.com/2006/mxml") with a manifest file. The include-namespaces option instructs compc to include all the components listed in that namespace's manifest file in the SWC file.

After you define the manifest file, you can compile the SWC file. The following command-line example compiles the components into the "http://mynamespace" namespace:

compc -source-path . 
-output c:/jrun4/servers/flex2/flex/WEB-INF/flex/user_classes/MyButtons.swc
-namespace http://mynamespace SimpleManifest.xml
-include-namespaces http://mynamespace

In a configuration file, these options appear as the following example shows:

<compiler>
    <source-path>
        <path-element>.</path-element>
    </source-path>
    <output>c:/jrun4/servers/flex2/flex/WEB-INF/flex/user_classes/        MyButtons.swc</output>
    <namespaces>
        <namespace>
            <uri>http://mynamespace</uri>
            <manifest>SimpleManifest.xml</manifest>
        </namespace>
    </namespaces>
</compiler>
<include-namespaces>
    <uri>http://mynamespace</uri>
<include-namespaces>

In your Flex application, you can access the components by defining the new namespace in the <mx:Application> tag, as the following example shows:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:a="http://mynamespace">
    <a:MyButton/>
    <a:MyOtherButton/>
</mx:Application>

Components in multiple namespaces

You can use the compc compiler to compile components that use multiple namespaces into a SWC file. Each namespace must have its own manifest file.

The following command-line example compiles components defined in the AcmeManifest.xml and SimpleManifest.xml manifest files:

compc -source-path . 
-output c:/jrun4/servers/flex2/flex/WEB-INF/flex/user_classes/MyButtons.swc
-namespace http://acme2006AcmeManifest.xml
-namespace http://mynamespace SimpleManifest.xml
-include-namespaces http://acme2006 http://mynamespace

In this case, all components in both the http://mynamespace and http://acme2006 namespaces are targeted and included in the output SWC file.

In a configuration file, these options appear as the following example shows:

<compiler>
    <source-path>
        <path-element>.</path-element>
    </source-path>
    <output>c:/jrun4/servers/flex2/flex/WEB-INF/flex/user_classes/        MyButtons.swc</output>
    <namespaces>
        <namespace>
            <uri>http://acme2006</uri>
            <manifest>AcmeManifest.xml</manifest>
        </namespace>
        <namespace>
            <uri>http://mynamespace</uri>
            <manifest>SimpleManifest.xml</manifest>
        </namespace>
    </namespaces>
</compiler>
<include-namespaces>
    <uri>http://acme2006</uri>
    <uri>http://mynamespace</uri>
<include-namespaces>

In your MXML application, you define both namespaces separately:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:simple="http://mynamespace" xmlns:acme="http://acme2006">
    <simple:SimpleComponent/>
    <acme:AcmeComponent/>
</mx:Application>

You are not required to include all namespaces that you define as target namespaces. You can define multiple namespaces, but use only one target namespace. You might do this if some components use other components that are not directly exposed as MXML tags. You cannot then directly access the components in the unused namespace, however.

The following command line example defines two namespaces, http://acme2006 and
http://mynamespace, but only includes one as a namespace target:

compc -source-path . 
-output c:/jrun4/servers/flex2/flex/WEB-INF/flex/user_classes/MyButtons.swc
-namespace http://acme2006AcmeManifest.xml
-namespace http://mynamespace SimpleManifest.xml
-include-namespaces http://mynamespace