<?xml version="1.0" encoding="utf-8"?>

<!--

    ADOBE SYSTEMS INCORPORATED
    Copyright 2008 Adobe Systems Incorporated
    All Rights Reserved.

    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the license agreement accompanying it.

-->

<!--- The Spark DefaultComplexItemRenderer class is an item renderer class that 
      displays a Flex component in a Group container. 
      Each component is wrapped in its own Group container. 
      Therefore, it is useful when the children of the container 
      are visual elements, such as Flex components. .  

       @see spark.components.Group
        
      @langversion 3.0
      @playerversion Flash 10
      @playerversion AIR 1.5
      @productversion Flex 4
-->
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
                autoDrawBackground="true">
    <!-- Setting autoDrawBackground will automatically draw the selection/rollover background rectangle for you.  
         If you would like to customize the appearance of your item renderer even further when 
         the item renderer is selected or hovered, you should turn this flag off and use states.  
         For more information on this and custom item renderer examples, check out the Flex documentation.
    -->
    
    <fx:Script>
        <![CDATA[
        
            import mx.core.IVisualElement; 
          
            [Bindable("dataChanged")]
            
            /**
             * @private
             */
            override public function set data(value:Object):void
            {
                super.data = value;
                
                //First lets remove everything from the contentGroup
                contentGroup.removeAllElements();
                
                //Then add the new items anew 
                if (value is Array)
                {
                    for (var i:int = 0; i < value.length; i++)
                    {
                        contentGroup.addElement(IVisualElement(value[i]));
                    }
                }
                else if (value is IVisualElement)
                {
                    contentGroup.addElement(IVisualElement(value));
                }
            }
        ]]>
    </fx:Script>
    
    <!--- The container used to wrap each Flex component defined in the host component. -->
    <s:Group id="contentGroup" verticalCenter="0" left="2" right="2" top="2" bottom="2" />

</s:ItemRenderer>
