PDA

View Full Version : what's the matter of my search engine?



richie
November 7th, 2002, 08:22 AM
hi there, i was doing a little search engine in flash mx, but it have some problems.

i load the content of a text file, there is a lot of names, and some data too, and i have to search a name for example, ok, when i first search a name, ok, i use the Selection.setSelection to highlight the name or whatever i search, but after the first time i search, i don't search anymore!!! what's the matter of this thing?

well let me show you guys the script:

on(release){
result = _root.textos.htmlText.indexOf(texto_pesquisa.text) ;
if(texto_pesquisa.text != "" && result >= 0){
Selection.setFocus(_root.textos);
Selection.setSelection(result, result + texto_pesquisa.text.length);
}else{
texto_pesquisa.text = "Nome inexistente...";
}
}

this script is attached to a button, within the "pesquisa" MC, wich is in the _root of the movie.

does anyone see what's wrong?

Dravos
November 7th, 2002, 11:04 AM
indexOf returns the first one that matches, is it possible it just keeps finding the same one??

If so then you need to create a substring after you found the first one and do an indexOf on that.

Hope this helps

richie
November 7th, 2002, 12:22 PM
ok, i'll try something like that, but, i don't see why is wrong, all the search dependes on what is on the text field:

result = _root.textos.htmlText.indexOf(texto_pesquisa.text) ;

every time i release the button, it takes the value and then do the search. And why when i first search and return the correct result, why the word didn't highlight? (Selection.setSelection(result, result + texto_pesquisa.text.length);) ???

thanks for the help, i tought doing diferent but not get there it...

richie
November 8th, 2002, 05:13 AM
YEEESS! Got it, this is the correct script that does the search:

on(release){
result = _root.textos.text.indexOf(texto_pesquisa.text);
if(texto_pesquisa.text != "" && result >= 0){
Selection.setFocus(_root.textos);
Selection.setSelection(result, result + texto_pesquisa.text.length);
}else{
texto_pesquisa.text = "Nome inexistente...";
}
}

didn't need the substr at all.