Copying Text To the User’s Clipboard in Flex
Sometimes there is a requirement or a desired usability enhancement for text to be placed on the user’s clipboard. This is a great little feature in an your application if you are able to provide it and have a good reason to. In Flex, it couldn’t be any easier. The setClipboard() function lives inside the System package. Simply call it like so:
...
import flash.system.System;
import mx.controls.Alert;
public function copyText(txt:String):void
{
System.setClipboard(txt);
Alert.show("'" + txt + "' has been copied to your clipboard");
}
...
Simple as that.







Is there any method to get text from the System clipboard without the use of AIR? The Ctrl+V have some problems. Sometimes it works but most of the times it doesn’t work. I want to override the Ctrl+V behavior and write a function on my own to copy the text from clipboard and paste it in the text input in flex. Anybody, please help me.
Hi,
this things will be very easy. is there any way to copy image to system clipboard in flex. ( not in Air). i taking about web based application. ( without taking image snapshot)
thanks,
nimesh nanda
@Nimesh, unfortunately the Flash platform only allows you to copy text to the clipboard, not images. If this is a strong requirement, however, you could look into doing it in Java and creating a Java applet.
Hi Kyle Hayes,
First of all many thanks for reply. is there any way to copy image to clipboard using javascript in flex application( Not in AIR).
i have pass Image in ” data:image/png;base64″ . it will display image when i am used window.open(“data:image/png;base64 “+ImageId);
But how to pass this format in System clipboard.
Thanks,
Nimesh nanda
From what I understand there is no reliable way to do it in JavaScript since JavaScript doesn’t have direct access to the clipboard. The most reliable way that people copy anything to the clipboard in the browser is through Flash, and it is only text.
Hi Kyle Hayes,
i saw one example which is copy image from SWF and paste to system clipboard. i would like to share with you. i am trying to do the same task in flex application.
http://danielmclaren.net/2008/03/copying-a-flash-movie-image-to-the-clipboard-in-ie
Note: this example works only in IE.
Thanks,
nimesh nanda
As I mentioned before, there is no reliable way to do it. As you can see that example is only for IE. I don’t know of a way to do it that will work in both browsers.
This is the only thing that I’m aware of:
http://dougmccune.com/blog/2007/06/03/save-a-snapshot-image-of-a-flex-app-without-a-server/
At that point you will have to tell the user to copy the image that opens up.
Thank you for posting this tip. This works a treat and is so simple.