3

I can't figure out how to fire a javascript event when rolling over a flash element even though it's on wmode:transparent.

I have tried to put a transparent sensor div over the flash element with the onMouseover event and it worked but the flash became useless and totally unclickable.

Appreciate Any ideas.

Thanks

CodeOverload
  • 47,274
  • 54
  • 131
  • 219
  • just from the top of my mind: put your movie in a div. Use jQuery to calculate where this div is positioned and track the mouse-position. Then you can figure out if the cursor is over the movie. links: http://docs.jquery.com/Tutorials:Mouse_Position and http://api.jquery.com/position/ – stian.net Jan 07 '11 at 22:26
  • Thanks, but it's not really clean, and it requires jQuery which is not reliable for pure javascript widgets. – CodeOverload Jan 07 '11 at 22:31
  • Your SWF becomes unclickable because you have the div z-indexed above the SWF. That's how z-index is intended to work. –  Jan 08 '11 at 07:38

2 Answers2

8

This is much simpler than ExternalInterface if you're looking for just simple mouse detection on an entire SWF.

Just target the <object> or <embed> tag that's embedding the SWF via Javascript.


document.getElementById("content-banner").onmouseover = over;

function over(evt)
{
 alert("moused over");  
}

http://jsfiddle.net/p7YkA/

  • why does `document.getElementById("content-banner").onmouseover` work but not `$("content-banner").mouseover()`? – theB3RV Feb 16 '15 at 19:26
1

Use the ExternalInterface and call a JavaScript method dispatching the event from Flash.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
  • I wish I could down vote the down vote. The OP did not fully explain that they were trying to get the entire SWF to fire the event in case of mouse interaction. He refers to a flash element (which to me seemed to be part of the flash movie, not the whole thing.) FWIW, I still prefer the ExternalInterface call with the event attached to the stage. – sberry Jan 11 '11 at 18:16
  • Thanks ;) Reading the accepted answer, the question makes sense. The down vote still seems a bit harsh as a reaction to a well-meant answer, even if it doesn't provide the perfect solution - just adding a comment and clarifying the question would have been enough. And to my mind, adding a comment after down voting should not be optional: What can you learn from your "mistakes", if others don't help you to improve your answers? – weltraumpirat Jan 11 '11 at 18:32