<mx:Model> tag implemented by the compiler


You use the <mx:Model> tag to declare a data model in MXML. An <mx:Model> tag is compiled into a tree of ActionScript objects; the leaves of the tree are scalar values.

MXML Syntax

You can place an <mx:Model> tag in a Flex application file, or in an MXML component file. The tag must have an id value. It cannot be the root tag of an MXML component. The <mx:Model> tag has the following syntax:

 <mx:Model id="modelID">
model declaration
</mx:Model>

or:

 <mx:Model id="modelID" source="fileName" />

where source specifies an external source, such as a file, for the data model. The external source can contain static data and data binding expressions. The file referenced in a source property resides on the server and not on the client machine. The compiler reads the source value and compiles the source into the application; the source value is not read at runtime.

The model declaration, either in-line in the tag or in the source file, must have a single root node that contains all other nodes. You can use MXML binding expressions, such as {myForm.lastName.text} in the model declaration. This way you can bind the contents of form fields to a structured data representation.

In the following example, the myEmployee model is placed in an MXML application file:

    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    ...
      <mx:Model id="MyEmployee">
        <root>
            <name>
               <first>Will</first>
               <last>Tuckerman</last>
            </name>
            <department>Accounting</department>
            <email>wtuckerman@wilsoncompany.com</email>
        </root>
      </mx:Model>
    ...
    </mx:Application>