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>
The flash almost certainly doesn't propagate the click event to its parent. Nothing you can do unless you wrote the flash, I suppose.
It is best to think of all swf's as having a z-order of infinity. Flash is on top and there is very little which can be done to stop that. On the other hand, if you have access to the code of the SWF itself, or if you can use another swf to load your current swf, you'll be able to use a couple of different Flash commands to address the JavaScript of the page. (ExternalInterface is your best bet).
Another alternative solution using onmousedown instead of onclick is provided by Darwin below.
the flash object will always catch the click and not automatically pass it along. you will have to build that functionality - catch onclick in flash and call JS-function.
what are you trying to accomplish?
I found this at http://progproblems.blogspot.com/2009/08/javascript-onclick-for-flash-embeded.html
wmode
totransparent
. This allows the object containing the flash to receive the javascriptonclick
.onmousedown
insted ofonclick
. In spite of usingwmode
transparent
, some browsers still wont call theonclick
, but they do callonmousedown
.The code looks like this:
It work for my needs =)
Try this easy solution cover the flash with div and put the click event on top div so flash will never grab the mouse.
do onclick event on a the object tag. (obejct tag supports mouse events). then grab the parent div via DOM.