Skip to main content
Participant
Mar 15, 2009 12:22 AM UTC
Answered

Copy selection to String

Is there anyway to grab the selected text in an flowComposer and copy that to a string for use in another control?
i've reviewed all of the textlayout api's relating to the selectionmanager and editmanager and cant seem to find a way to do so, or convert a TextScrap to a string.... any clues anyone?
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
Mar 15, 2009 3:35 AM UTC
This isn't too tough to do, but it might not be completely obvious. You were headed in the right direction with the Selection/EditManager. I think the easiest way would probably be to call createTextScrap() on the selection/edit manager, which will give you a TextScrap object that has a public property 'textFlow' which contains only the selected range of text. You can then pass that text flow to the exporter which will convert that text flow to a plain string.

To get your string you would do something like (didn't test this, but I think it should be close):
var scrap:TextScrap = editManager.createTextScrap();
var selectedText:String = TextFilter.export(scrap.textFlow, TextFilter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String;

It seems like it would be a good idea to build a convenience method into the SelectionManager class that does this for you, but I don't think there is anything like that right now.

Hope this helps!
-Brent

2 replies

Participant
Mar 15, 2009 6:03 AM UTC
worked perfectly. thanks alot Brent. you're a life saver =)
i had been busily tracing through the textscraps contents using
a trace of the scrap passed through ObjectUtil.toString() and was having no luck at all. i was stuck in the assumption that the textFlow property of a scrap was a reference to teh originating flow of the scrap.
Translate
Correct answer
Mar 15, 2009 3:35 AM UTC
This isn't too tough to do, but it might not be completely obvious. You were headed in the right direction with the Selection/EditManager. I think the easiest way would probably be to call createTextScrap() on the selection/edit manager, which will give you a TextScrap object that has a public property 'textFlow' which contains only the selected range of text. You can then pass that text flow to the exporter which will convert that text flow to a plain string.

To get your string you would do something like (didn't test this, but I think it should be close):
var scrap:TextScrap = editManager.createTextScrap();
var selectedText:String = TextFilter.export(scrap.textFlow, TextFilter.PLAIN_TEXT_FORMAT, ConversionType.STRING_TYPE) as String;

It seems like it would be a good idea to build a convenience method into the SelectionManager class that does this for you, but I don't think there is anything like that right now.

Hope this helps!
-Brent
Translate