下载 MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white"
horizontalAlign="left"
fontSize="12" initialize="init()">
<mx:Array id="coutries">
<mx:Object label="Dlic" data="D"/>
<mx:Object label="China" data="C"/>
<mx:Object label="America" data="A"/>
<mx:Object label="British" data="B"/>
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:Label text="查询:"/>
<mx:Canvas>
<mx:TextInput id="searchText"/>
<mx:Image id="img" source="" right="3" verticalCenter="0"/>
</mx:Canvas>
<mx:Button label="go" icon="@Embed('assets/Input.PNG')" click="findHandler(event)"/>
</mx:ApplicationControlBar>
<mx:List id="cb" dataProvider="{collView}" width="150"/>
<mx:Script>
<![CDATA[
import mx.collections.IViewCursor;
import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.collections.Sort;
import mx.collections.SortField;
[Embed("assets/SuccessComplete.PNG")]
private var okIcon:Class;
[Embed("assets/Serious.PNG")]
private var errorIcon:Class;
[Bindable]
private var collView: ICollectionView = null;
private var sort:Sort = new Sort();
private function init():void
{
//排序
collView = new ArrayCollection(coutries);
sort.fields = [new SortField("label", true)];
collView.sort = sort;
//务必进行刷新,否则,排序不会自动生效
collView.refresh();
}
private function findHandler(event:MouseEvent): void
{
var vc: IViewCursor = collView.createCursor();
if (vc.findFirst({label:searchText.text}))
{
cb.selectedItem = vc.current;
img.source = okIcon;
}
else
{
cb.selectedItem = null;
img.source = errorIcon;
}
}
]]>
</mx:Script>
</mx:Application>
实例效果,在独立的窗口观看<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" backgroundColor="white"
horizontalAlign="left"
fontSize="12" initialize="init()">
<mx:Array id="coutries">
<mx:Object label="Dlic" data="D"/>
<mx:Object label="China" data="C"/>
<mx:Object label="America" data="A"/>
<mx:Object label="British" data="B"/>
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:Label text="查询:"/>
<mx:Canvas>
<mx:TextInput id="searchText"/>
<mx:Image id="img" source="" right="3" verticalCenter="0"/>
</mx:Canvas>
<mx:Button label="go" icon="@Embed('assets/Input.PNG')" click="findHandler(event)"/>
</mx:ApplicationControlBar>
<mx:List id="cb" dataProvider="{collView}" width="150"/>
<mx:Script>
<![CDATA[
import mx.collections.IViewCursor;
import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.collections.Sort;
import mx.collections.SortField;
[Embed("assets/SuccessComplete.PNG")]
private var okIcon:Class;
[Embed("assets/Serious.PNG")]
private var errorIcon:Class;
[Bindable]
private var collView: ICollectionView = null;
private var sort:Sort = new Sort();
private function init():void
{
//排序
collView = new ArrayCollection(coutries);
sort.fields = [new SortField("label", true)];
collView.sort = sort;
//务必进行刷新,否则,排序不会自动生效
collView.refresh();
}
private function findHandler(event:MouseEvent): void
{
var vc: IViewCursor = collView.createCursor();
if (vc.findFirst({label:searchText.text}))
{
cb.selectedItem = vc.current;
img.source = okIcon;
}
else
{
cb.selectedItem = null;
img.source = errorIcon;
}
}
]]>
</mx:Script>
</mx:Application>