Using MXML components

MXML components are MXML files that you use as custom tags in other MXML files. They encapsulate and extend the functionality of existing Flex components. Just like MXML application files, MXML component files can contain a mix of MXML tags and ActionScript code. The name of the MXML file becomes the class name with which you refer to the component in another MXML file.

Note: You cannot access MXML component URLs directly in a web browser.

The following example shows a custom ComboBox control that is prepopulated with list items:

<?xml version="1.0"?>
<!-- MyComboBox.mxml -->

<mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml">
    <mx:ComboBox >
      <mx:dataProvider>
            <mx:Array>
               <mx:String>Dogs</mx:String>
               <mx:String>Cats</mx:String>
            <mx:String>Mice</mx:String>
            </mx:Array>
      </mx:dataProvider>
   </mx:ComboBox>
   
</mx:VBox>

The following example shows an application that uses the MyComboBox component as a custom tag. The value * assigns the local namespace to the current directory.

<?xml version="1.0"?>
<!-- MyApplication.mxml -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns:local="*">
   <mx:Panel title="My Application" marginTop="10" marginBottom="10"
      marginLeft="10" marginRight="10" >

      <local:MyComboBox/>

   </mx:Panel>
</mx:Application>

The following figure shows the application rendered in a web browser window:


MXML component example.

For more information about MXML components, see Building an Application with Multiple MXML Files in Developing Flex Applications.

You can also define custom Flex components in ActionScript and the Flash MX 2004 authoring tool. For more information, see Using ActionScript


Version 1.5

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000025.htm