Macromedia flex 2 Manual

Page of 254
Implementing a template component
197
The implementation of the topRow and bottomRow properties lets you specify any Flex 
component as a value, as the following example shows:
<?xml version="1.0"?>
<!-- templating/MainTemplateLink.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:MyComp="myComponents.*"
    height="700" width="700">
    <mx:Panel paddingTop="10" paddingBottom="10" 
        paddingRight="10" paddingLeft="10">
    
        <MyComp:MyTemplateComponent id="myTComp2">
            <MyComp:topRow>                        
                <mx:TextArea text="top component"/>
            </MyComp:topRow>
            <MyComp:bottomRow>
                <mx:LinkButton label="Link 1"/>         
                <mx:LinkButton label="Link 2"/>
                <mx:LinkButton label="Link 3"/>
            </MyComp:bottomRow>
        </MyComp:MyTemplateComponent>
    </mx:Panel>
</mx:Application>
In this example, the top component is a 
TextArea
 control, and the bottom components are 
two 
LinkButton
 controls.
Implementing a template component 
The sectio
 shows an example of a template 
component named MyTemplateComponet. Flex provides you with two primary ways to 
create template components: 
Create properties with general data types, such as 
UIComponent
 or 
Container
Create properties with the type IDeferredInstance. 
The following sections describes these methods.
Using general data types in a template component
This section shows one implementation of the component MyTemplateComponent shown in 
the section 
 by defining the properties topRow 
and bottomRow to be of type 
UIComponent
. Users of the component can then specify any 
object to these properties that is either an instance of the UIComponent class, or an instance 
of a subclass of UIComponent.