Sergey Senkov
Sergey Senkov

Reputation: 1540

AS3 AIR addEventListener on Clipboard change

I have code :

import flash.desktop.Clipboard; 
import flash.desktop.ClipboardFormats; 

if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){ 
    var text:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT); 
} 

It works only when I manually check clipboard. Is any way to addEventListener on Clipboard.generalClipboard to catch it was changed by user?

Upvotes: 0

Views: 85

Answers (1)

SushiHangover
SushiHangover

Reputation: 74174

No, there is no existing Event that exists in Flash/Air for changes on OS clipboard (that I know about)

There are native OS APIs for this of course, you could write an ANE to hook the native event and raise an ActionScript Event, but you would need to do this for each OS that your Air app is going to run on.

You could poll the clipboard on a timer event (I seen it done), grab the contents and compare it to the last time you polled it, but this is really a dirty way to do things and depending on what the user last pasted to the clipboard, you could end up retrieving some really large objects that would need to be hashed in some form (sha/md5) to determine if the next time things changed or not... A lot of wasted processing and garbage collection could cause your app to appear to stop responding to the user.

Upvotes: 2

Related Questions