Macromedia flex 2 Manuale

Pagina di 254
About MXML components
81
Creating composite MXML components
A composite MXML component is a component that contains multiple component 
definitions within it. To create a composite component, you specify a container as its root tag, 
and then add Flex components as children of the container. 
For example, the following component contains an address form created by specifying a 
Form
 
container as the root tag of the component, and then defining several children of the Form 
container. One of the 
<mx:FormItem>
 tags contains a reference to the 
<MyComp:StateComboBox>
 tag that you created in 
<?xml version="1.0"?>
<!-- mxml/AddressForm.mxml -->
<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:MyComp="*">
    <mx:FormItem label="NameField">
        <mx:TextInput/>
    </mx:FormItem>
    <mx:FormItem label="Street">
        <mx:TextInput/>
    </mx:FormItem>
    <mx:FormItem label="City" > 
        <mx:TextInput/>
    </mx:FormItem>
    <mx:FormItem label="State" > 
        <MyComp:StateComboBox/>
    </mx:FormItem>
</mx:Form>
The following application file references the AddressForm component in the 
<AddressForm>
 
tag:
<?xml version="1.0"?>
<!-- mxml/MyApplicationAddressForm.mxml-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
    xmlns:MyComp="*" >
    <MyComp:AddressForm/> 
</mx:Application>