Friday, April 15, 2011

Working with clipboard in AIR: Part 2

Today we'll learn about clipboard data formats in AIR applications.

You might have not thought about it before, but when you work with the system clipboard (aka when you copy, paste) you often write and read data of different formats. For example, if you copy a bitmap, you store bitmap data in your clipboard, but when you copy a piece of text - you store data in string format.

Many of the Clipboard object methods require you to specify the type of data format when you use them, for example, if you want to set data to a clipboard object, you need to specify the format of the data you are passing.

In the next example I am going to pass a String value to a

myClip.setData(ClipboardFormats.TEXT_FORMAT, "Some text here!");

Here's the full list of all standard ClipboardFormats types:

BITMAP_FORMAT - a BitmapData object
FILE_LIST_FORMAT - an array of File objects
HTML_FORMAT - a line in HTML format
TEXT_FORMAT - a String object
URL_FORMAT - a String object
RICH_TEXT_FORMAT - Rich text format data
FILE_PROMISE_LIST_FORMAT - file promise list

You are not limited to these formats, though. However, these are the standards and will often open more possibilities for the user, for example, copying images from your application to another image editor (and vice versa) or copying text from your AIR program to Word.

You can still set your own formats though. For example, you want to copy an object of your own custom class called Contact, which has properties like first name, second name, age, sex, telephone and so on. You can set your own format and call it something like "animal" to later (when you need to get data from the clipboard) be able to identify that you have something stored in your clipboard under the format "animal" and identify it and work with it.

The format is set like this:

myClip.setData("animal", myAnimalObject);

And that's all for now.

Thanks for reading!

Related:

Working with clipboard in AIR: Part 1
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