Copy to clipboard from Flash (a lesson)

14 04 2008

You may well have appeared at my humble blog hunting for a method of copying data to the clipboard directly from Flash as I have had one of these posted for a while. The method I wrote uses Actionscript to call a JavaScript that writes the content you wish to copy into an HTML text input field in a hidden div via the DOM model and then uses JavaScript to copy it to the System clip. I have been using this method on production sites for ~6 months and it works great but as it turns is totally unnecessary ;) The following barely documented function could have saved me (and you) the whole run around…

[code lang="actionscript"]

this.createTextField("in_txt", this.getNextHighestDepth(), 10, 10, 160, 120);
in_txt.text = "lorum ipsum...";
System.setClipboard(in_txt.text);

[/code]

I guess sometimes as a Developer you just have to accept that you did things in the wrong way (although in my defence it works) but rather than hush it up I figured this is a lesson learned that I may as well share ;)

Who knows, someone may find my massively over the top JS Dom Model access version useful for something one day in circumstances where JS can do something Flash can’t?…