Skip to main content
Inspiring
January 8, 2009
Answered

Accessing raw text of TextFlow and performing a search

  • January 8, 2009
  • 5 replies
  • 1190 views
I am trying to figure out the best way to perform a search within a TextFlow to locate a specific piece of text (either a word or set of words).
I have had a hard time figuring out how to actually gain access to the raw text of the TextFlow that is loaded. Once that is loaded, I need to be able to search through that text, find the location of the text, and show that container.

Essentially add search capability to the Pagination example.

The only thing I can think of that seems like it may work would be to export the TextFlow into an XML file, then perform the search on the XML file. Once that is done, I would have to figure out which position in the xml file the text was located, and load the container with that position....

Surely there is a better way?
Thanks, Tim
This topic has been closed for replies.
Correct answer tpf70
I found a sample that does essentially what you are proposing. The CheckSpelling sample is a great place to start to go through the text in the TextFlow.
Thanks,
Tim

5 replies

Participant
March 17, 2009
this works fine for me:

var s:String=TextFilter.export(_flow,TextFilter.PLAIN_TEXT_FORMAT,ConversionType.STRING_TYPE) as String;
Adobe Employee
March 17, 2009
I think what you are looking for is the "SpellCheckAdornment" example in the Flash examples download. See:

http://labs.adobe.com/downloads/textlayout.html

At the bottom of the page is a link for Flash examples.
tpf70AuthorCorrect answer
Inspiring
January 9, 2009
I found a sample that does essentially what you are proposing. The CheckSpelling sample is a great place to start to go through the text in the TextFlow.
Thanks,
Tim
rstawarz
Participant
March 17, 2009
Where is the 'CheckSpelling' example you are referring to? Do you have a link of where I can find it at?

Thanks,
-Ryan
Adobe Employee
January 8, 2009
You could do an export to plain text, and search that to find the offset in the TextFlow. This should work if the text you are using does not have discretionary hyphens (since they would be filtered out by the plain text filter). However, I would expect you would getter better performance by searching paragraph by paragraph. Iterate through all the paragraphs in the TextFlow, and get the text of each paragraph from the textBlock: paragraph.textBlock.content.rawText.
tpf70Author
Inspiring
January 9, 2009
Robin,
I looked at exporting, but I am having a problem with that functionality.
A very simple example fails to work for me.
I reported it in a new thread...
my other thread here

Thanks for your help,
Tim
Adobe Employee
January 8, 2009
I think so - here's how I'd reccomend approaching the problem.

Given a TextFlow I'd do a getFirstLeaf. That returns a FlowLeafElement. I'd then look at the FlowLeafElement.text property to access the text for matching. To advance to the next leaf element use FlowLeafElement.getNextLeaf.

You'll have to do some book keeping when you find a match to figure out the absolute position of the beginning of the match. Next step would be to use textFlow.flowComposer.findControllerIndexAtPosition to figure out which container has the matched text.

Adding niceties you could search a paragraph at a time by taking advantage of the limitElement parameter to getNextLeaf. After calling getFirstLeaf call getParagraph to find the paragrah and use that as the limit element. To advance to the next paragraph use null as the limit element and call getParagraph again for the new limit element.

Hope that helps.
Richard