<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal"
    creationComplete="init()" viewSourceURL="srcview/index.html">
    
    <mx:Script>
        <![CDATA[
            import com.benclinkinbeard.collections.FlattenedList;
            import com.benclinkinbeard.examples.City;
            import com.benclinkinbeard.examples.State;
            import mx.collections.ArrayCollection;
            
            [Bindable]
            private var sourceList:ArrayCollection = new ArrayCollection();
            
            [Bindable]
            private var flatList:FlattenedList;
            
            private function init():void
            {
                var ky:State = new State( "Kentucky", "KY" );
                ky.cities.addItem( new City( "Taylor Mill" ) );
                ky.cities.addItem( new City( "Fort Thomas" ) );
                ky.cities.addItem( new City( "Lexington" ) );
                ky.cities.addItem( new City( "Louisville" ) );
                ky.cities.addItem( new City( "Covington" ) );
                sourceList.addItem( ky );
                
                var il:State = new State( "Illinois", "IL" );
                il.cities.addItem( new City( "Chicago" ) );
                il.cities.addItem( new City( "Peoria" ) );
                il.cities.addItem( new City( "Springfield" ) );
                sourceList.addItem( il );
                
                var oh:State = new State( "Ohio", "OH" );
                oh.cities.addItem( new City( "Cincinnati" ) );
                oh.cities.addItem( new City( "Dayton" ) );
                oh.cities.addItem( new City( "Columbus" ) );
                oh.cities.addItem( new City( "Cleveland" ) );
                sourceList.addItem( oh );
                
                flatList = new FlattenedList( sourceList.source, "cities" );
            }
            
            private function flatListLabelFunction( item:Object ):String
            {
                if( item is State )
                {
                    return item.name;
                }
                else // item is City
                {
                    return "     " + item.name;
                }
            }
            
        ]]>
    </mx:Script>
    
    <mx:VBox>
        <mx:Label text="Source List" />
        <mx:List dataProvider="{ sourceList }" labelField="name" />
    </mx:VBox>
    
    <mx:VBox>
        <mx:Label text="Flattened List" />
        <mx:List dataProvider="{ flatList }" labelFunction="flatListLabelFunction" width="200" />
    </mx:VBox>
    
</mx:Application>