Due to security issues, flash memory cannot access the buffer unless the action is a click (or user interaction) with the flash.
Because of this, simply calling clip.setText will never work. Even calling it from a random button, the onclick handler will not work, since it is not a click on the flash object.
It is as it is.
So what ZeroClipboard does is βglueβ or add an invisible flash element to the object of interest to you. When you click on an element, you do not run the usual javascript onclick for this element, you fire the onclick flash video event.
Hope this makes sense.
So, to βstickβ ZeroClipboard to an element, you can do what you did, which is right, or you can call:
clip.glue(element);
You can glue several elements without problems.
So, to set the text, the action must begin by clicking on the Flash object. There are three ways to do this, according to the documentation.
Using data-clipboard-text
You can set the βdata-clipboard-textβ attribute to any text you like, and it will be copied automatically.
for example, for your example (copy βcopy this text!β):
<button id="my-button" data-clipboard-text="copy this text!">Copy to Clipboard</button>
Using data-clipboard target
Or you can set "data-clipboard-target" to any id element, and ZeroClipboard will try to get this innerText element;
eg. (copies of "Copy to clipboard")
<button id="my-button" data-clipboard-target="my-button">Copy to Clipboard</button>
Using the dataRequested Event
And finally, you can copy the text in the callback. If none of these attributes is set, then the dataRequested callback will be called, in which you can set the text as you want.
for example (copies of "Setting text in a callback ...")
<html> <body> <script src="js/jquery-1.9.1.js"></script> <script type="text/javascript" src="zc/ZeroClipboard.js"></script> <button id="my-button">Copy to Clipboard</button> <script language="JavaScript"> ZeroClipboard.setDefaults({ moviePath: "zc/ZeroClipboard.swf" }); var clip = new ZeroClipboard( $("button#my-button") ); clip.on( 'dataRequested', function ( client, args ) { clip.setText("Setting the text in a callback..."); </script> </body> </html>
Keeping a warning in the callback stops working for me for some reason, so just be aware of it.
Conclusion
So, note that in all three examples, the copy event comes from a click on the flash object. As far as I know, there is no way to copy it only from javascript without user interaction.
For more information, read the ZeroClipboard instructions: https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md