通过 JavaScript 单击到 Flash 对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10947254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:35:14  来源:igfitidea点击:

Click to Flash object via JavaScript

javascriptjqueryflash

提问by tunarob

Is it possible to trigger click event on Flash object via JavaScript?

是否可以通过 JavaScript 在 Flash 对象上触发点击事件?

采纳答案by Ja?ck

Yes and no. You canuse the ExternalInterfaceto simulate click events in your Flash project, provided they don't care about the event source (i.e. human or not).

是和否。您可以使用ExternalInterface来模拟您的 Flash 项目中的点击事件,前提是它们不关心事件源(即人类与否)。

However, one of the features in Flash that's particularly obtuse about the click event source is the File Selectiondialog. It's not possible to trigger that without a real click from a real user (as far as the browser is concerned); this would actually be a potential security risk if possible. If I remember correctly, this was possible before FP 9 and we exploited this behavior for our file uploader. This started to cause issues once they fixed it, but I'm glad they did so :)

但是,Flash 中关于单击事件源的功能之一是“文件选择”对话框。如果没有来自真实用户的真正点击(就浏览器而言),就不可能触发它;如果可能的话,这实际上是一个潜在的安全风险。如果我没记错的话,这在 FP 9 之前是可能的,我们为我们的文件上传器利用了这种行为。一旦他们修复它,这开始引起问题,但我很高兴他们这样做了:)

The typical way to overcome this limitation is by creating a transparent Flash object and positioning a layer over it that shows a button image; the click event will eventually hit the Flash object and trigger a user click event.

克服此限制的典型方法是创建一个透明的 Flash 对象并在其上放置一个显示按钮图像的图层;点击事件最终会命中 Flash 对象并触发用户点击事件。

回答by Future2020

I never tested this, so it is just thought

我从来没有测试过这个,所以只是认为

Note please note that you should have a certain div which will capture the clicks.

请注意,您应该有一个特定的 div 来捕获点击。

In Actionscript To simulate a click event, it is possible to use.

在 Actionscript 中要模拟一个点击事件,可以使用。

 element.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));

So why not creating an external function that will dispatch the event once receiving the invoke from JavaScript using externalinterface? Of course this is very rough but it may well work.

那么为什么不创建一个外部函数,一旦从 JavaScript 使用 externalinterface 接收到调用,它就会调度事件呢?当然,这是非常粗糙的,但它可能会很好地工作。

Actionscript:

动作脚本:

import flash.external.*;

function simulateButtonClick() 
{ 
// Here goes your code
} 
ExternalInterface.addCallback("invokeSimulateButtonClick", simulateButtonClick); 

Javascript:

Javascript:

 ExternalInterface.addCallback("invokeSimulateButtonClick", YOUR_VARIABLES);

回答by Kh?i

No you can't capture clicks on embedded elements, unless it's behind a div or something.

不,您无法捕获对嵌入元素的点击,除非它位于 div 或其他东西后面。