Javascript – Detecting Flash “Click” Event in JavaScript Across Browsers

event handlingeventsflashjavascript

Is there a way JavaScript can detect clicks (or mousedown, mouseup) that happen on Flash objects?

I have tried:

  • Attaching the 'mouseup', 'mousedown', and 'click' events to the Flash object using attachEvent/addEventListener
  • Directly attaching the 'onmouseup', 'onmousedown', 'onclick' events inline on the Flash object
  • Switching from event 'bubbling' to event 'capturing' (only works in Firefox/Safari)

I need this to work in IE6+, Firefox 2+, and Safari 3+.

Thanks for any help! -Dave

Best Answer

I found this at http://progproblems.blogspot.com/2009/08/javascript-onclick-for-flash-embeded.html

1) Set the param wmode to transparent. This allows the object containing the flash to receive the javascript onclick.
2) Use onmousedown insted of onclick. In spite of using wmode transparent, some browsers still wont call  the onclick, but they do call onmousedown.
The code looks like this:

<div onmousedown="clickBanner(1)">
<object>
<param name="movie" value="3.swf">
<param name="wmode" value="transparent" />
<embed wmode=transparent allowfullscreen="true" allowscriptaccess="always" src="3.swf"></embed>
</object>
</div>

It work for my needs =)