Skip to main content
Participant
March 15, 2009
Answered

Copy selection to String

  • March 15, 2009
  • 2 replies
  • 501 views
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 has been closed for replies.
Correct answer
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
March 15, 2009
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.
Correct answer
March 15, 2009
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