My Name Is Rich

Icon

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.

This movie requires Flash Player 9

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!

About Me

My name is Richard Perez and I am an alumni of Rochester Institute of Technology. This is my personal blog where I like to post about anything that insterests me. Which can range from design, programming, family, and tech gadgets. Currently, I work at HZDG in New York City as an Interactive Flash Developer. I love design and combining that with flash makes my day ten times better.

Categories

Calendar

August 2009
M T W T F S S
« Jul   Oct »
 12
3456789
10111213141516
17181920212223
24252627282930
31