<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="srv.getElements(0,20000)" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
[Bindable] private var ffCount:Number = 0;
[Bindable] private var ffTime:Number = 0;
[Bindable] private var d:ArrayCollection;
private var oneStepDownSearchText:String = "";
private var ffStartDate:Date;
private function ff(item:Object):Boolean
{
if ((oneStepDownSearchText == "") || (item["__includedInFilter__" + oneStepDownSearchText] != null))
{
ffCount++;
if ((item.id.toString()).indexOf(filterText.text) == 0)
{
item["__includedInFilter__" + filterText.text] = true;
return true;
}
}
return false;
}
]]>
</mx:Script>
<mx:AMFChannel id="myamf" uri="http://www.jamesward.com/census/messagebroker/amf"/>
<mx:ChannelSet id="channelSet" channels="{[myamf]}"/>
<mx:RemoteObject id="srv" destination="census-ro" showBusyCursor="true" channelSet="{channelSet}" endpoint="/census/messagebroker/amf?gzip=true">
<mx:result>
d = new ArrayCollection(event.result as Array);
d.filterFunction = ff;
d.addEventListener(CollectionEvent.COLLECTION_CHANGE, function(event:CollectionEvent):void {
if (event.kind == CollectionEventKind.REFRESH)
{
ffTime = ((new Date()).time - ffStartDate.time);
}
});
</mx:result>
</mx:RemoteObject>
<mx:FormItem label="Search the based on id (numbers):">
<mx:TextInput id="filterText" restrict="0-9">
<mx:change>
ffCount = 0;
if (filterText.text.length > 0)
{
oneStepDownSearchText = filterText.text.substr(0, -1);
}
else
{
oneStepDownSearchText = "";
}
ffStartDate = new Date();
d.refresh();
</mx:change>
</mx:TextInput>
</mx:FormItem>
<mx:DataGrid dataProvider="{d}"/>
<mx:Label text="ff was called {ffCount} times"/>
<mx:Label text="filter took {ffTime} ms"/>
</mx:Application>