12.2. Copy and Paste

Although Flex 2 allowed the ability to read the clipboard, it was limited to text only, and there was no way to write to the clipboard. AIR has removed these restrictions and given full access to read and write all types of data to and from the system clipboard. This section demonstrates how to copy and paste image files in and out of an AIR application.

12.2.1. Paste

The first half of this application will address the ability to paste data into an AIR application. This involves the use of the Clipboard class to access the clipboard and read in the file. Start off by creating a new AIR application named Chapter12_Paste. This will create a new file named Chapter12_Paste.mxml, which we will build on throughout this section. Listing 12-4 will show the completed version of this application.

We'll start off by bringing in the necessary import statements. This application will require the flash.filesystem.File. We will also be using the mx.controls.Alert and mx.controls.Image classes. Copy the contents of Listing 12-10 into the Chapter12_Paste.mxml file.

Example 12-10. The necessary import statements
<mx:Script>
  <![CDATA[
    import mx.controls.Alert;
    import mx.controls.Image;
    import flash.filesystem.File;
]]>
</mx:Script>

Next we'll add in a simple button to simulate the paste action. Add the Button component in Listing 12-11 to the Chapter12_Paste.mxml file. To accomplish this using Ctrl-v on Windows or Cmd-v on Mac, you can use the Flex KeyboardEvent class (see ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.