Thursday, April 14, 2011

Working with clipboard in AIR: Part 1

Today we will start learning about clipboards in AIR.

Copy, paste, drag & drop - those are the standard ways for the user to interact with an application, so it might be a good idea to include these features in your program. For example, if you are making an image editor, users should have the ability to drag and drop an image file from their desktop straight to your application window and be able to edit it, as well as copy and paste parts of images in your application.

All these features are similar to each other - we simply move/copy data from one place to another. The only difference is the user interaction.

When the user is dragging an element of the interfact to another place and then releases his mouse, the data is copied or moved from its initial location.

When the user is using copy feature, he selects an element he wants to copy using a menu item, hotkeys or a button, then does the same operation to paste the copied data somewhere else.

Both of the features require a place to store the data at. In AIR this temporary storage is called clipboard.

There are 2 types of clipboards that we can work with in AIR.

The first one is the system clipboard, which you might already know. This is the buffer that stores everything we copy, for example, we want to copy a paragraph of text from Notepad to Microsoft Word - once we hit Copy (or use Ctrl+C), the data is sent to the clipboard.

The second one is the clipboard that is special to AIR applications.

AIR refers to both of the clipboard types the same way, and you can access them through flash.desktop.Clipboard objects.

You can do three things to a Clipboard objcet - add data to it, get data from it and remove data from it.

To refer to the system clipboard, you can use a static property Clipboard.generalClipboard:

var sysClip:Clipboard = Clipboard.generalClipboard;

To refer to the AIR supported clipboards:

var clip:Clipboard = new Clipboard();

That is all for now.

Thanks for reading!

Related:

Working with clipboard in AIR: Part 2
Working with clipboard in AIR: Part 3
Working with clipboard in AIR: Part 4
Working with clipboard in AIR: Part 5
Working with clipboard in AIR: Part 6
Working with clipboard in AIR: Part 7
Working with clipboard in AIR: Part 8
Working with clipboard in AIR: Part 9
Working with clipboard in AIR: Part 10

No comments:

Post a Comment