Filter Data with ArrayCollection
June 6th, 2007
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.)
Last 5 posts in actionscript
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Roman Numeral/Arabic Convertion AIR App - Johnny V Now Available - December 25th, 2008
- How to convert Roman Numerals and Arabic numbers in ActionScript 3 - December 17th, 2008
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
- Flash Player 10 Dynamic Sound Generation - May 20th, 2008
Last 5 posts in as3
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Guitar Synth for Flash - February 27th, 2009
- Abstract Thermometer AIR app - January 22nd, 2009
- Roman Numeral/Arabic Convertion AIR App - Johnny V Now Available - December 25th, 2008
- How to convert Roman Numerals and Arabic numbers in ActionScript 3 - December 17th, 2008
Last 5 posts in flash
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Roman Numeral/Arabic Convertion AIR App - Johnny V Now Available - December 25th, 2008
- How to convert Roman Numerals and Arabic numbers in ActionScript 3 - December 17th, 2008
- Flash Player 10 Pure Flash Keyboard using SampleDataEvent - September 3rd, 2008
- Using Flash Player 10 to produce Dynamic Musical Notes - May 20th, 2008
Last 5 posts in Flex
- HOWTO Create a Facebook App using FlexBuilder - June 24th, 2009
- Adobe Evangelist Daniel Dura visits Travelocity - April 15th, 2008
- Yahoo Maps ActionScript 3.0 Released - February 11th, 2008
- Papervision 3D 2.0 / Great White Example - December 26th, 2007
- Tidbit #3 - testing additions to your code - Control Variable - November 28th, 2007
Entry Filed under: Flex, actionscript, as3, flash
3 Comments Add your own
1. Nolan | July 24th, 2007 at 8:45 am
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.
2. joshspoon | July 25th, 2007 at 2:28 pm
Thanks I’m working on finding that out right now
3. Kausar Khan | January 25th, 2008 at 2:47 pm
Usefull info what I was searching for. Thank you again.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed