使用按钮粘贴剪贴板中的文本

发布于 2024-08-13 11:11:02 字数 690 浏览 1 评论 0原文

我有控制栏按钮“复制”、“剪切”和“粘贴”,它们应该从剪贴板复制/粘贴一些文本/对象。

复制/剪切效果很好。 使用 CTRL+V 和上下文菜单粘贴也可以正常工作。

但是,当我尝试通过控制栏按钮单击处理程序访问剪贴板时,它会抛出错误,

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

我知道这是安全问题。

方法 Clipboard.generalClipboard.getData() 可用于读取内容 系统剪贴板,但仅当它 从事件处理程序中调用 处理 flash.events.Event.PASTE 事件。

但我必须实现粘贴控制栏按钮。我必须这样做吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夕色琉璃 2024-08-20 11:11:02

要克服 Flash Player 施加的安全限制,您可以使用 Flash Local 共享对象模拟系统剪贴板的功能,就像此处首次建议的那样 http://joeberkovitz.com/blog/2008/12/12/clipboard-using-local-shared-objects/ 或使用Javascript API 通过ExternalInterface 从剪贴板检索数据。

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.

混浊又暗下来 2024-08-20 11:11:02

我唯一能找到的是使用自定义上下文菜单进行粘贴的能力。您可以找到 这里有关于如何执行此操作的示例。我尝试自己调度“粘贴”事件,播放器似乎以某种方式检测到粘贴来自上下文菜单或键盘 - 不完全确定它是如何做到这一点或为什么会这样。我希望其他人可以提供更多说明,但与此同时,上下文菜单是否有效?

更新:我认为没有任何方法可以强制粘贴事件。我一直在运行一些测试,似乎让此事件分派并允许在没有安全错误的情况下调用 Clipboard.generalClipboard.setContents 方法的唯一方法是响应全局粘贴事件,该事件只能分派“从上下文菜单或键盘事件(ctrl+V 或等效平台)安全地“”。抱歉。

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.

不弃不离 2024-08-20 11:11:02

在其他编程环境中,我发现从按钮触发剪贴板粘贴操作不起作用,因为在粘贴操作发生之前,按钮本身获得焦点,远离目标编辑控件。难道是这样的情况吗?

In other programming environment, I have found that triggering a clipboard paste action from a button doesn't work because the button itself gets the focus, away from the target edit control, before the paste action takes place. Could this be this case?

や莫失莫忘 2024-08-20 11:11:02

为了避免异常安全,事件的目标必须是应用程序的阶段对象。我没有在任何文档中找到此信息,这是我自己的经验。希望它有效。

In order to avoid the exception security, the target of the event MUST BE the stage object of the application. I didn't found this information in any documentation, it is from my own experience. Hope it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文