javascript onclick event over flash object

Pedro picture Pedro · Sep 18, 2009 · Viewed 74.9k times · Source

I have one embed flash movie inside one div, I put one javascript onclick event handler in the main div, but isn't catching the click, what is wrong?

Code:

   <div id="top-box-player" onclick="alert('Hi Bananas!');">
     <object width="400" height="300">
        <param name="movie" value="general.swf">
        <embed src="./swf/general.swf" width="400" height="300">
        </embed>
     </object>
   </div>

Answer

Darwin picture Darwin · Nov 15, 2010

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