hey guys i have a site entirely built on flash. its basically an e-magazine with lots of textual data. i need to implement a full text search where the user enters search terms in a text field and i need to highlight the occurrence of this search term within the textual contents inside this e-magazine
in a way its similar to what you do within a browser search or pdf search where after typing your search term they highlight all occurrences of this search term within the webpage / pdf document
what is the best way开发者_如何学C to do this? any ready component / solution / code available? thanks in advance
It sounds like something you should have envisaged doing before starting your site. You could have created a specific class, or overridden the TextField class, in order to implement a method which given a specific word would look for occurrences of this word in each TextField you want searchable by using the String search() or match() method and apply some formatting to this word in order to highlight it.
This method could be an event listener, although I would rather use the Signal class for something like this. Anyway, here's a basic example
public class SearchableTextField extends Sprite { private var textfield:TextField; public function SearchableTextField(dispatcher:EventDispatcher ) { dispatcher.addEventListener( CustomEvent.HIGHTLIGHT , searchEventListener ); } private function searchEventListener( event:CustomEvent ):void { var searchTerm:String = event.searchTerm; if( textfield != null ) { //find every occurrence the searchTerm //in textfield.text and format it } } }
Use google - you may fetch google search results from flash, and show inside your flash thing with fancy design.
Doing your own fulltext search will use quite alot of effort - you will need to have indexing too, so if google works for you - use it.
精彩评论