copy snippets

How to implement copy-to-clipboard functionality that works with Flash 10

Tagged copy, clipboard, copy-to-clipboard, clippy, flash 10, flash  Languages 

Use mojombo's Clippy which can be downloaded from GitHub.

How to create a custom button

  • First create your button and save it as a PNG file.
  • Change library.xml to use your button.
  • Customize the code behind the button by modifying clippy.hx. You can, for example, remove the "Copy to clipboard" label.
  • Set the width and height of the button. You have to set it in almost all files (compile.hxml, library.xml, etc).
  • Compile the SWF file:
swfmill simple library.xml library.swf && haxe compile.hxml


There are no good alternatives that I know of. I tried ZeroClipboard and other solutions, but they were full of bugs and not customizable.

Copy-to-clipboard with plain Javascript

Tagged clipboard, copy, javascript  Languages javascript, html
var Copy2Clipboard = {
  init: function(selector) {
    var btns = document.querySelectorAll(selector);
    for (var i = 0, len = btns.length; i < len; i++) {
      var btn = btns[i]
      btn.addEventListener('click', function(event) {
        var btn =
        try {
          var textarea = document.getElementById(btn.getAttribute('data-target'))
          if (textarea == null) {
            alert("copy-to-clipboard target is undefined")
          var successful = document.execCommand && document.execCommand('copy')
          if (successful) {
            btn.innerHTML = 'Copied...'
          } else {
            alert("Press Ctrl+C or Cmd+C to copy")
        } catch (err) {
          console.log('Oops, unable to copy')

<textarea id="embed-code">
  This will be copied to the clipboard.