Follow Flex After Dark on Twitter

MXML Namespaces

If you want to use custom components (outside of the mx or flash packages), first you'll have to setup a namespace tell Flex where to find your custom controls. (Using custom controls in your MXML can be a little tricky at first.)

See the end of this document for some links to external information about Namespaces.

The Default Namespace

http://www.adobe.com/2006/mxml

An MXML document created by Flex Builder will automatically bind the mx namespace to the Flex Core Library.

Using Custom Namespaces

Example, setup a namespace referencing the package my.custom.controls:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   xmlns:mycontrols="my.custom.controls.*"
>

The "xmlns:mycontrols" declares an XML namespace, "mycontrols".

You can now refer to your custom components in the MXML using the namespace.

<mycontrols:CustomComponent id="abc"
   ...
/>

The declaration of your (mycontrols:CustomComponent) element has the following parts:

  • mycontrols - The namespace you setup, tells Flex the package your components are in
  • CustomComponent - The name of the class/component in the package

Of course you can setup several package/namespace bindings in MXML.

Related Links:

Related Docs
Recent Docs
Random Docs