<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/29/defining-a-custom-label-function-on-a-flex-tree-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            private function tree_labelFunc(item:XML):String {
                var label:String;
                switch (item.localName()) {
                    case "league":
                        label = item.@title;
                        break;
                    case "team":
                        label = item.@name;
                        break;
                    case "stadium":
                        label = item.name;
                }
                return label;
            }
        ]]>
    </mx:Script>

    <mx:XML id="mlb" source="mlb.xml" />

    <mx:Tree id="tree"
            dataProvider="{mlb.league}"
            labelFunction="tree_labelFunc"
            width="300"
            rowCount="8" />

</mx:Application>