User Guide
20 Creating Flex Components
The main application, or any other MXML component file, references the StateComboBox
component, as the following example shows:
<?xml version="1.0"?>
<!-- intro/MyApplication.mxml -->
<!-- Include the namespace definition for your custom components. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:MyComp="*">
<!-- Use the filename as the MXML tag name. -->
<MyComp:StateComboBox/>
</mx:Application>
The MXML tag name for a custom component is composed of two parts: the namespace
prefix, in this case
MyComp, and the tag name. The namespace prefix tells Flex where to look
for the file that implements the custom component. The tag name corresponds to the
filename of the component, in this case StateComboBox.mxml. Therefore, a file named
StateComboBox.mxml defines a component with the tag name of
<namespace:StateComboBox>.
As part of the
<mx:Application> tag, the main application file includes the following
namespace definition:
xmlns:MyComp="*". This definition specifies that the component is in
the same directory as the main application file, or in a directory included in the ActionScript
classpath. For more information on deploying MXML components, see Chapter 7, “Creating
Simple MXML Components,” on page 77.
A best practice is to put your custom components in a subdirectory of your application. That
practice helps to ensure that you do not have duplicate component names because they have a
different namespace. If you stored your component in the myComponents subdirectory of
your application, you would specify the namespace definition as
xmlns:MyComp="myComponents.*".