Macromedia flex 2 Manuale

Pagina di 254
82
Creating Simple MXML Components
If you include child tags of the root container tag in an MXML component file, you cannot 
add child tags when you use the component as a custom tag in another MXML file. If you 
define an empty container in an MXML file, you can add child tags when you use the 
component as a custom tag.
The following example defines an empty Form container in an MXML component:
<?xml version="1.0"?>
<!-- mxml/EmptyForm.mxml -->
<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml"/>
This component defines no children of the Form container, therefore, you can add children 
when you use it in another MXML file, as the following example shows:
<?xml version="1.0"?>
<!-- mxml/MainEmptyForm.mxml-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:MyComp="*">
    <MyComp:EmptyForm>    
        <mx:FormItem label="Name">
            <mx:TextInput/>
        </mx:FormItem>
    </MyComp:EmptyForm>
</mx:Application>
The AddressForm.mxml file specifies the Form container as its root tag. Because you define a 
container as the root tag of the MXML component, you are creating a subclass of that 
container, and you can reference all of the properties and methods of the root tag when using 
your MXML component. Therefore, in the main application, you can reference all of the 
properties of the Form container in the MXML tag that corresponds to your custom 
component, or in any ActionScript code in the main application. However, you cannot 
reference properties of the children of the Form container.
NO
TE
The restriction on child tags refers to the child tags that correspond to visual 
components. Visual components are subclasses of the UIComponent component. You 
can always insert tags for nonvisual components, such as ActionScript blocks, styles, 
effects, formatters, validators, and other types of nonvisual components, regardless of 
how you define your custom component.