问题
Is it possible to capture rich text when pasting into Flash? Using a Flex TextEditArea, I can paste richly formatted text within Flash itself, but if I try to paste from an external source (say web page, microsoft word, etc) it comes in as plain text. Same for the reverse: if I copy rich text from within Flash, and paste to an external source, it goes out as plain text.
回答1:
I'm part way there, so far I've got this:
<s:RichEditableText paste="pasteHandler(event)" width="100%" height="100%"/>
protected function pasteHandler(event:Event):void
{
if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.HTML_FORMAT)) {
var txt:RichEditableText = event.target as RichEditableText;
var html:String = Clipboard.generalClipboard.getData(ClipboardFormats.HTML_FORMAT) as String;
var mgr:EditManager = txt.textFlow.interactionManager as EditManager;
mgr.pasteTextScrap(new TextScrap(TextConverter.importToFlow(html, TextConverter.TEXT_FIELD_HTML_FORMAT)));
event.stopImmediatePropagation();
}
}
It gets some formatting in. But now there's a problem with font size -- anything that's not a default font size, is extremely tiny. Normal font stays normal. Large fonts become tiny fonts. Small fonts become 1-pixel high dots.
回答2:
have a look at TinyMCE or some other editor, they have options for pasting word text, perhaps you might be able look at how their parsing it and emulate that. If you can target flex4 flash player 10 you might have a look at http://labs.adobe.com/technologies/textlayout/ which might help you as this post on adobes forums states
来源:https://stackoverflow.com/questions/3892707/paste-rich-text-into-flash