<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:components="components.*" initialize="onInitialize()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.managers.CursorManager;
import mx.utils.ObjectUtil;
import mx.utils.ArrayUtil;
import flash.utils.Timer;
import flash.events.TimerEvent;
[Bindable]
private var myArrayCollection:ArrayCollection;
private var siteMapObjectFromServer:Object =
{articleID: "1", title: "Home", children: [
{articleID: "2", title: "About Us" },
{articleID: "3", title: "Store Locations", children: [
{articleID: "9", title: "Kentucky", children: [
{articleID: "10", title: "Paducah" },
{articleID: "11", title: "Lexington" },
{articleID: "12", title: "Louisville" },
]},
{articleID: "13", title: "Indiana", children: [
{articleID: "14", title: "Indianapolis" },
{articleID: "15", title: "Evansville" },
]},
{articleID: "16", title: "Ohio", children: [
{articleID: "17", title: "Columbus" },
{articleID: "18", title: "Cincinnati" },
]},
]},
{articleID: "4", title: "Products", children: [
{articleID: "5", title: "Product 3" },
{articleID: "6", title: "Product 2" },
{articleID: "19", title: "Product 1" },
{articleID: "20", title: "Product 4" },
]},
{articleID: "7", title: "Services" },
{articleID: "8", title: "Contact Us" }
]};
private function onInitialize():void
{
getDataFromServer();
}
private function getDataFromServer():void
{
CursorManager.setBusyCursor();
var myTimer:Timer = new Timer(500, 1);
myTimer.addEventListener("timer", onTimer);
myTimer.start();
}
private function onTimer(event:TimerEvent):void
{
CursorManager.removeBusyCursor();
myArrayCollection = new ArrayCollection(ArrayUtil.toArray(ObjectUtil.copy(siteMapObjectFromServer)));
}
private function onRefreshButtonClick():void
{
getDataFromServer();
}
]]>
</mx:Script>
<mx:HBox width="100%" paddingTop="5" paddingRight="5">
<mx:Button id="btRefreshTree" label="Refresh" icon="@Embed(source='/assets/arrow_refresh.png')" right="10" bottom="10" click="onRefreshButtonClick()"/>
<mx:CheckBox id="cbSort" label="Sort" />
<mx:CheckBox id="cbRememberOpenState" label="Remember Open State" />
</mx:HBox>
<components:SiteMap id="mySiteMap" siteMapIDField="articleID" siteMapLabelField="title" dataProvider="{myArrayCollection}" sortItems="{cbSort.selected}" rememberOpenState="{cbRememberOpenState.selected}" />
</mx:Application>