Count item count for ComboBox selected item
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.*;
private var myCursor:IViewCursor;
public function countLast(theCursor:IViewCursor):int {
var counter:int=0;
var mark:CursorBookmark = theCursor.bookmark;
while (theCursor.moveNext()) {
counter++;
}
theCursor.seek(mark);
return counter;
}
public function countFromSelection():void {
myCursor.findFirst(myCB.selectedItem);
var count:int = countLast(myCursor);
ta1.text += myCursor.current.label + " at " + count;
}
</mx:Script>
<mx:ArrayCollection id="myAC">
<mx:Object label="A" data="AA" />
<mx:Object label="B" data="BB" />
<mx:Object label="C" data="CC" />
</mx:ArrayCollection>
<mx:ComboBox id="myCB" rowCount="7" dataProvider="{myAC}" change="countFromSelection();" />
<mx:TextArea id="ta1" height="200" width="175" />
</mx:Application>
Related examples in the same category