简体   繁体   English

点击Flash对象通过JavaScript

[英]Click to Flash object via JavaScript

是否可以通过JavaScript触发Flash对象上的click事件?

Yes and no. 是的,不是。 You can use the ExternalInterface to simulate click events in your Flash project, provided they don't care about the event source (ie human or not). 可以使用ExternalInterface模拟Flash项目中的单击事件,前提是它们不关心事件源(即人类与否)。

However, one of the features in Flash that's particularly obtuse about the click event source is the File Selection dialog. 但是,Flash中对Click事件源特别迟钝的功能之一是“ 文件选择”对话框。 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. 如果我没记错的话,这在FP 9之前是可能的,我们将这种行为用于我们的文件上传器。 This started to cause issues once they fixed it, but I'm glad they did so :) 这一问题一旦解决就开始引起问题,但我很高兴他们这样做了:)

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; 克服此限制的典型方法是创建一个透明的Flash对象,并在其上放置一个显示按钮图像的图层; the click event will eventually hit the Flash object and trigger a user click event. click事件最终将命中Flash对象并触发用户单击事件。

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中要模拟click事件,可以使用。

 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? 那么为什么不创建一个外部函数,一旦从使用外部接口的JavaScript接收调用就调度事件? Of course this is very rough but it may well work. 当然这非常粗糙,但它可能会奏效。

Actionscript: 动作:

import flash.external.*;

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

Javascript: 使用Javascript:

 ExternalInterface.addCallback("invokeSimulateButtonClick", YOUR_VARIABLES);

不,你不能捕获嵌入元素的点击,除非它在div或其他东西后面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM