• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

How do I copy RTF data from one TextArea to a clip board and copy it to another TextArea while presevering the formatting in Flex 3?

I have a text area that is display RTF data and I am including a "copy to clipboard button" so they can paste it directly into another text area. When I highlight the text a copy and paste it works, but when I try to do it from a button, it doesnt.

I have tried setting the textarea.htmltext but it doesnt seem to like it when its done through the system copy.

Can you point me in the right direction?
  • 3
1 Solution
Flex is limited in it's programmable interaction with the clipboard. Yes it works when you e.g. press Ctrl-C to copy, but in Flex the only command you have for working with the clipboard is System.setClipboard, which only takes a string. What you copy via Ctrl-C is much more than a string.

The restriction is for security purposes - would you want a Flex app you might not trust copying object data to the clipboard?

Look at AIR for much better Clipboard interaction (with the Clipboard class) - when you allow AIR apps to run on your desktop a higher level of trust is implicitly assumed.

Only other option I can think of is to 'fake your own clipboard' in the following example, but I know this is not really what you want as you'd have to force the user to also use the 'Paste' button.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
			private var mockHTMLClipboard:String = "";
			private function onCopy():void
				mockHTMLClipboard = rte.htmlText; 
			private function onPaste():void
				ta.htmlText = mockHTMLClipboard;
	<mx:HBox width="100%" horizontalCenter="0" verticalCenter="0" horizontalAlign="center" height="332">
		<mx:VBox height="100%">
			<mx:Button label="Copy" id="btnCopy" click="onCopy();"/>
			<mx:RichTextEditor id="rte" title="Title">
		<mx:VBox height="100%">
			<mx:Button label="Paste" id="btnPaste" click="onPaste();"/>
			<mx:TextArea id="ta" height="100%" width="226"/>

Open in new window

Polite request for an update - please remember to close questions if your issue is resolved, or reply if you need further assistance ;)
20lbMonkeyAuthor Commented:
This is a great answer and it helped me tremendously. Sorry that I didnt close it our earlier. I actually took a few days off for the holiday weekend.
Great - glad it helped, hope you got a good break !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now