After watching a Lynda.com tutorial realized I didn’t have to do as much work to filter data.
the filterFunction is a public property of the ICollectionView witch is the class that the ArrayCollection extends from.
So this function/method is accessible to a ArrayCollection.
[as]
< ?xml version="1.0" encoding="utf-8"?>
< ![CDATA[
import mx.collections.*;private var collectionArray:Array;
[Bindable]
private var collectionData:ArrayCollection;private function init():void
{
collectionArray = [{first: 'Dave', last: 'Matthews'},
{first: 'Amy', last: 'Grant'},
{first: 'Bilbo', last: 'Baggins'},
{first: 'Jessica', last: 'Tandy'},
{first: 'Paris', last: 'Hilton'}];
collectionData = new ArrayCollection(collectionArray);
}public function filter():void {
//pass my filter function to the method w/ no ()
// you must also refresh it
collectionData.filterFunction = filterFirst;
collectionData.refresh();}
// function see's if the searchField's text is equal to the "first" object of the collectionData//if true it show results, if false it shows nothing
private function filterFirst(item:Object):Boolean
{
return (item.first == searchField.text)}
]]>
[/as]
Problems w/ this:
- I have not found a way to match with just typing in “Da” and it is case-sensitive
- When you type in a non-matching string it will not reset to beginning state. (I’m sleepy so maybe that’s why I can’t figure it out.)
Try looking into Regular Expressions, which make it easy to have case-insensitive searches with fragments of the word.
return (item.first == searchField.text)
becomes:
return item.first.match(new RegExp(searchFiel.text, “i”))
The second parameter tells the RegEx to ignore case sensitivity.
Thanks I’m working on finding that out right now
Usefull info what I was searching for. Thank you again.