简体   繁体   中英

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).

However, one of the features in Flash that's particularly obtuse about the click event source is the File Selection dialog. 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 :)

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.

I never tested this, so it is just thought

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

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

 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.

Actionscript:

import flash.external.*;

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

Javascript:

 ExternalInterface.addCallback("invokeSimulateButtonClick", YOUR_VARIABLES);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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