PDA

View Full Version : Database / Search Engine "Game" and Array in LoadVars


piratefish
02-03-2006, 08:50 PM
First a little explanation. This is a stupid idea that I came up with after having a strange talk with my friend. I ran with the idea and came up with this pseudo-search engine/database for all of his opinions and then you can search using a keyword to see what his opinion is.

The code and everything works but the problem that I see is that we'll have to run through the entire database to find an answer, even if it at the very beginning of the arrays.

Is there a more efficient way of doing this or is the following code the best way to go?



opinion=new Array("Cats are cool, we need more cats in the world","I don't like cats");
keyWords=new Array("cats,kittens","monkeys,baboons");
trace(opinion);



//Button Function
button.onRelease = function() {
searchField = searchBox_txt.text;
trace(searchField);
searchField=searchField.toLowerCase();
trace(searchField);
//Goes through the keywords array
for (i=0; i<keyWords.length; i++) {
newTerm = keyWords[i];
trace(newTerm);
newTerm = newTerm.split(",");
//New For loop for the search field
for (a=0; a<newTerm.length; a++) {
trace(newTerm[a]);
trace(searchField);
if (newTerm[a] == searchField) {
//Displaying the text
trace(opinion[i]);
opinion_txt.text = opinion[i];
break;
}
}
}
};


Thanks for your help.

Edit: How could I take that "database" out of flash, put it in a text document and still have it as an array? Meaning is it possible to do an array in a text document just like you would make one in flash ("data1","data2","data3",etc.)?

Edit 2: I found the answer to my second question. A great tutorial for it is here. http://actionscript.org/showMovie.php?id=635