Sorry, rattled that last one off a bit fast and made a couple of mistakes.

Anyway, an ArrayCollection has a property called "filterFunction" which you can add a callback to like so in Flex:

(In Flash you can use the Array.filter property - you don't get the ArrayCollection)

//load your XML into here.
private var myTitles:ArrayCollection

//store your search string here - done in the search for function
private var mySearchString:String;

public function myFilter(item:Object):Boolean {

//add your test on the item in here - this is an entry in the array collection, e.g.
   return item.title.indexOf(mySearchString) == 0;
}

function searchFor(str:String):void {
   mySearchString = str;

   // the filter function will return only the matching category's data
   myTitles.filterFunction = myFilter;
// refresh the data in myTitles with to only show the ones with the search string.
   myTitles.refresh();
}

Steven Loe wrote:
I have a plan, but I suspect that it not a great approach:

I have an alpha sorted xml file containing hundreds of titles. I'd like to 
create an
array of items whose beginning contains my search string.
So if the search string is "Ba" and this is my list, I'd want the 3rd and 4th 
items
only:

10 Things I Hate About You
Agent Cody Banks
Baby Story, A
Back to the Future
Yoga for Back Care
Zona de Batalla

My plan is: Do a binary search on the keyCode of the first letter, get all of 
the items
that start with "B". Then, use substring to see which of these items start with 
"Ba"
and add these to my array. What do you think? Is there a better way to approach 
this?

Thanks for your time


      
____________________________________________________________________________________
Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



--

Glen Pike
01736 759321
www.glenpike.co.uk <http://www.glenpike.co.uk>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to