Skip to main content
Inspiring
Jan 8, 2009 3:11 AM UTC
Answered

Accessing raw text of TextFlow and performing a search

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 is closed to new replies. Start a new post to keep the conversation going.
tpf70Correct answer
Inspiring
Jan 9, 2009 10:37 PM UTC
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

7 replies

Participant
Mar 17, 2009 3:25 PM UTC
this works fine for me:

var s:String=TextFilter.export(_flow,TextFilter.PLAIN_TEXT_FORMAT,ConversionType.STRING_TYPE) as String;
Translate
Adobe Employee
Mar 17, 2009 4:50 AM UTC
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.
Translate
tpf70AuthorCorrect answer
Inspiring
Jan 9, 2009 10:37 PM UTC
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
Translate
rstawarz
Participant
Mar 17, 2009 2:32 AM UTC
Where is the 'CheckSpelling' example you are referring to? Do you have a link of where I can find it at?

Thanks,
-Ryan
Translate
Adobe Employee
Jan 8, 2009 4:06 AM UTC
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.
Translate
tpf70Author
Inspiring
Jan 9, 2009 10:41 PM UTC
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
Translate
Inspiring
Jan 8, 2009 4:06 AM UTC
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
Translate