Aug 29, 2009 0
Flash Tip: Copy To Clipboard
Well, I was working a small project and I realized I needed to be able to copy content to the user’s clipboard. I know this is doable since I’ve seen it done in many, many flash sites and applications. So after a quick look through the Flash Help Docs I came across a little function called System.setClipboard().
Check out the example below to see it in action. All you have to do is type your own text and press copy. Simple and easy.
1 2 3 4 5 6 7 8 9 10 11 12 | import flash.system.System; import flash.events.MouseEvent; this.copyButton.mouseChildren = false; this.copyButton.buttonMode = true; this.copyButton.addEventListener(MouseEvent.CLICK, this._click); function _click(event:MouseEvent):void { System.setClipboard(this.copyField.text); this.copyButton.labelField.text = "Copied!!"; } |
The way this code works is that after you’ve typed your text and press the copy button. System.setClipboard() is called and a string is passed as a parameter. And that’s really all of the grunt work. Nothing more or less.
I’ve uploaded a zip file containing all the source files for your viewing pleasure.
Hope you found this example useful!