Apollo Beta Sneak: Clipboard
Depending on the dominant browser for your web application, and the security settings therein, you may have been able to work with text on the system clipboard via JavaScript. If you’re a Flash developer, the Flash Player allows you to send text to the clipboard, but not to get anything at all from it. This leaves you branching out to JavaScript, checking the browser and settings, and then potentially being able to work only with text. Historically, this has been painful for all parties involved, but this is about to change! The Apollo Beta will introduce system clipboard support for text, bitmap data, and even lists of files.
This works through the use of a the ClipboardManager class. The ClipboardManager class has a data property the represents the system clipboard. You can put text, bitmap data, or files on the clipboard, or retrieve them from it using that data property. You don’t get access to the ClipboardManager.data property however, unless you’re inside an method enclosure called by the clipboard manager. What?
It essentially works like this:
- Your application listens for events that should trigger clipboard access (cut or paste)
- The application then calls the static method ClipboardManager.accessClipboard( func )
- The ClipboardManager.accessClipboard() method takes a function to call when the clipboard is available as an argument
- From within that function, and only within that function, you can access the ClipboardManager.data property directly
The code representation of that looks something like this:
document.getElementById( "btnPaste" ).addEventListener( "click", myEventHandler );
function myEventHandler()
{
apollo.ClipboardManager.accessClipboard( myClipboard );
}
function myClipboard()
{
var myData = apollo.ClipboardManager.data.dataForFormat(
apollo.TransferableDataFormats.BITMAP_FORMAT,
apollo.TransferableTransferMode.CLONE_PREFERRED );
}
There’s even support for multiple representations of what’s headed out to the clipboard. For example, you might chose to have a comma-separated text block for a list of data objects, but you can also put the data in a file and put the file on the clipboard. In this fashion, it’s actually up to the target application to decide what clipboard representation to use, and then to access and apply that data accordingly. This holds true for incoming data as well.
When you think of the types of data that end up on the clipboard, some pretty interesting possibilities start coming to mind. Ever press the “print screen” button? That ends up on the clipboard as bitmap data. Ever highlight a bunch of files and then copy them somewhere? What if you pasted that group of files into an Apollo application for additional processing such as being upload to a server? Here’s an example that allows you to copy a graphic from a web page (bitmap data), paste that into your Apollo application, and then send it back to the clipboard and onto the desktop.
June 9th, 2007 at 12:22 am
Why did you “copy image location” vs. copy image? Could you have?
June 9th, 2007 at 6:21 am
Great! But those Captivate presentations are too damn slow!
June 9th, 2007 at 1:05 pm
Philip,
Sharp eyes! I could have, and I would have ended up with the raw bitmap data on the clipboard. It’s easy enough to encode this data and save it to disk, insert it into the application, etc. At least that’s the idea…
I was experiencing some problems with encoding the bitmap data however, where I would end up with seemingly random parts of the image being transparent. I think this may be a bug in the alpha, but I need to clarify with the engineering team. In the meantime, I wanted to get this information out before a certain deadline…
In this case, “Copy Image Location” gives me a URL (text) on the clipboard, which I then use URLLoader to pull the bits to a local file. I reference that local file in the IMG I’m inserting into the HTML page. Then I send that file to the clipboard and paste it on the desktop. So the text and file list items work as advertised, but I’m still investigating the bitmap encoding problem.
Thanks for keeping me honest!
Kevin
June 9th, 2007 at 1:09 pm
Quentin,
Ha! LOL! I think so too!
I can of course shorten the duration, but I think I might investigate other options. Do you have any suggestions? An open source screen capturing/recording software perhaps? In the meantime, I’ll take care to keep the duration short.
Thanks,
Kevin
June 9th, 2007 at 1:57 pm
Let me digg into Captivate’s options…
I’ll let you know, thanks for answering!
June 30th, 2007 at 1:12 pm
Kevin, I found a work-around for dragging an image in, but I’ve run into what looks like a different issue using the clipboard. Woeful hack is at http://blog.softwareodyssey.com/2007/06/flex-native-drag-n-drop-image-from.html
August 9th, 2007 at 9:46 am
Can you please provide the full code for the example?