views:

5018

answers:

5

Hi Guys,

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>
+1  A: 

The flash almost certainly doesn't propagate the click event to its parent. Nothing you can do unless you wrote the flash, I suppose.

Tor Haugen
+1  A: 

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?

oberhamsi
I'm trying to change the css class of another page object when we click on the swf
Pedro
+5  A: 

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

//This is what your AS code should look like:
import flash.external.ExternalInterface;
import flash.events.MouseEvent;

root.addEventListener( MouseEvent.CLICK, useExternal, true );

function useExternal( event:MouseEvent):void
{
    //swfClickFunction is defined in JavaScript
    ExternalInterface.call( "swfClickFunction" );
}

Unless you are able to do either of the above, Flash will "eat" your mouse events and there is nothing which can be done about that.

Christopher W. Allen-Poole
I try in flash with on(release) { getURL("javascript:highlightform()"); } and work fine!!! But your solution is valid too, so thanks!
Pedro
A: 

I have the exact same problem. I'm trying to add a click event to a flash movie that's been on the site for a long time. I don't have any flash development experience and I don't have access to the source code. All I'm trying to do is to ad a anchor tag around the animation so when the user clicks on it another window opens. I thought that it would be a 5 minutes change, but I gather from this thread that it's not possible to do unless I change the flash code... * sight *

AlexFreitas
A: 

do onclick event on a the object tag. (obejct tag supports mouse events). then grab the parent div via DOM.

Elijan