PDA

View Full Version : HELP = "List"+"Text Field Component"+"Array"


thefjk
01-10-2006, 02:58 AM
Info:
Here's the whole story, I've made an Array with a lot of Websites, then it sends the info to a List Component where, when the user click, it shows the Website, WebSite Details and URL on seperate text boxex. There is a button which opens the browser from the selected item's URL. Complicated? It gets worse!

Help:
Now i want to add a TextField which woul'd Update my List according to what a user types, letter by letter, or when they click search, but when the text field is empty display the original List...

CAN SOMEONE HELP ME...!! I'M STUCK AND HAVE NO MORE IDEAS... Actionscript is too hard sometimes...!

Code Used:(As The dataProvider, 1 Item Only!)
var list:Array = [
{label:"AC", icon:"acIcon", data:"http://www.ac.com/", info:"AC Stuff."}];

Heres a SAMPLE (http://www.geocities.com/thefjk/web_list.swf)

PS: Any Search type (like must press-button-type, is also appritiated!) They will all be useful... :D


Thanks THEFJK!

chrisxkelley
01-10-2006, 05:15 AM
the solution i can think of, is to create a change listener for the search box. then, when it is changed, run a function with the current value of the search box, call it "searchText" for now, and that function will take the value and look for it in each array item with by joining their respective items and using indexOf(searchText) to try and find the search string in them. if the text is found in an array item, then add it to the new dataprovider.

complicated? make sense?
i'll make a little sample:
we're assuming the following -


the search TextInput component has an instance of "searchText"
the array name and items are the same as the code sample you posted
the list instance name is "listBox"


//create a new object to hold the search array
var newList:Array = new Array();
// create your listener
var searchListener:Object = new Object();
searchListener.change = function(eventObject:Object)
{
var n:Number = 0;
// for every item in the array
while (n < list.length)
{
// do the search function
search(n);
//then increase the counter
n++;
}
//after all of the searches are done, set the new array as the dataprovider
listBox.dataProvider = newList;
};
// add the listener to the search textInput component
searchText.addEventListener("change", searchListener);
function search(n):Void
{
// join all of the elements in the array as a string to index them
var arrayString:String = list[n].join(" ");
//if the string contains the search text
if (arrayString.indexOf(searchText.text)) {
//add that array item to the new array
newList.push(list[n]);
}
}


the syntax is all correct but i'm not sure if it works or if you'll implement it correctly so let me know. if not, i can take a look at your source and help you further

thefjk
01-10-2006, 02:19 PM
Thanks Chris X, i'll check the code! Get back to ya!

chrisxkelley
01-10-2006, 11:02 PM
cool, oh and just thought of something.

as the first even to happen inside the change function, delete the newList array, and then create it again so it is blank.


delete newList;
var newList:Array = new Array();