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?
20lbMonkeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mplordCommented:
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">
 
	<mx:Script>
		<![CDATA[
			private var mockHTMLClipboard:String = "";
 
			private function onCopy():void
			{
				mockHTMLClipboard = rte.htmlText; 
			}
			
			private function onPaste():void
			{
				ta.htmlText = mockHTMLClipboard;
			} 
			
		]]>
	</mx:Script>
 
	<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:RichTextEditor>
		</mx:VBox>
		<mx:VBox height="100%">
			<mx:Button label="Paste" id="btnPaste" click="onPaste();"/>
			<mx:TextArea id="ta" height="100%" width="226"/>
		</mx:VBox>
	</mx:HBox>
	
</mx:Application>

Open in new window

0
mplordCommented:
Polite request for an update - please remember to close questions if your issue is resolved, or reply if you need further assistance ;)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
mplordCommented:
Great - glad it helped, hope you got a good break !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.