I have control bar buttons Copy, Cut, and Paste and they suppose to copy/paste some text/objects from and to clipboard.
Copy/Cut works fine. Paste using CTRL+V and context menu works fine as well.
But when I'm trying to access Clipboard via control bar button click handler it throws error
SecurityError: Error #2179: The Clipboard.generalClipboard object may only be read while processing a flash.events.Event.PASTE event.
at flash.desktop::Clipboard/getObjectReference()
at flash.desktop::Clipboard/convertNativeFormat()
at flash.desktop::Clipboard/getOriginal()
at flash.desktop::Clipboard/getData()
... 2 more
I know that this is security issue.
Method Clipboard.generalClipboard.getData() may be used to read the contents of the system Clipboard, but only when it is called from within an event handler processing a flash.events.Event.PASTE event.
But I have to implement paste control bar button. Had do I do that?
To overcome this security limitation imposed by Flash Player you can either simulate the functionality of system clipboard with Flash Local shared objects like it was first suggested here http://joeberkovitz.com/blog/2008/12/12/clipboard-using-local-shared-objects/ or use Javascript API via ExternalInterface to retrieve the data from the Clipboard.
The only thing I've been able to find is the ability to paste using a custom context menu. You can find an example on how to do that here. I've tried dispatching "paste" events myself and the player seems to somehow detect that the paste comes from the context menu or keyboard - not entirely sure how it does that or why that is. I hope someone else can provide more clarification, but in the mean time, would a context menu work?
UPDATE: I don't think there's any way to force a paste event. I've been running some tests and it seems the only way to get this event to dispatch and allow the Clipboard.generalClipboard.setContents method to be called without the security error is to respond to a global paste event, which can only be dispatched "safely" from a context menu or keyboard event (ctrl+V or the platform equivalent.) Sorry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With