Skip to main content
Inspiring
December 1, 2009
Question

TextScrap.toString()

  • December 1, 2009
  • 2 replies
  • 1740 views

Given that the TextScrap.toString() method causes a compiler error - how do I convert a TextScrap instance into a simple text string?

(flashx.textLayout.edit.TextScrap)

Here is an example of code that won't compile:-

private function copy():void

{

   var scrap:TextScrap=txt.copy(); //returns a TextScrap instance.

   Clipboard.generalClipboard.clear();

   Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT,scrap.toString());  // This line won't compile.

   Clipboard.generalClipboard.setData('TextScrap',scrap);

}

It's for adobe AIR - but that's not relevant to the issue, which is that scrap.toString() causes an error:-

Error: Call to a possibly undefined method toString through a reference with static type flashx.textLayout.edit:TextScrap.

So is it possible to get a string representation of TextScrap ?

This topic has been closed for replies.

2 replies

February 15, 2011

Thanks to 'mrapcznski's post. Now I can convert the TextScrap to text(String).

            import flashx.textLayout.tlf_internal;
            use namespace tlf_internal;

            var theScrap:TextScrap = pasteOperation.textScrap;

            var pasteText:String = String(theScrap.tlf_internal::endMissingArray[0].text);

Above didn't work for my TLF 2.0 code.

This is how it worked there.

     var theScrap:TextScrap = pasteOperation.textScrap;                 
     var pasteText:String = TextConverter.export(theScrap.textFlow,
                            TextConverter.PLAIN_TEXT_FORMAT,
                            ConversionType.STRING_TYPE).toString();

December 1, 2009

Could you use the PlainTextExporter instead?

Inspiring
December 2, 2009

That's what I ended up doing.  It's not ideal.  The export generates a string that represents the entire document.  So then I have to apply substring to calculate the selection.

ADOBE! - We need a way to access a TextScrap as a String.

December 2, 2009

I'll log a request that we add a getText method to TextRange and TextScrap, but I don't expect that this will happen for 1.0.

For now you could use the tlf_internal function get textFlow on TextScrap and then use the plain text filter on the result.