The DOM is like an Ogre — it has layers… lots and lots of layers…
This way of thinking was key to the solution I found to a very interesting problem a friend of mine presented.
Problem: Integrating a Flash game that uses the up and down arrows into a new site with drop down menus. The menus need to sit on top of the flash game, so wmode=transparent must be used. As we know, Z-index does not work when a flash piece is running in the default “window” mode. Because the page is longer than the viewable area, it needed to scroll and in IE7, when hitting the up and down arrows in the game, the whole page would scroll. Essentially when the flash piece runs in wmode=transparent|opaque, IE7 captures the keystrokes along with the flash piece.
What do we want: We want the user to be able to use the up and down arrows without the page scrolling and the key presses registering in the game like it does in all other browsers.
Solution: overflow:auto
I wrapped the flash content div in a wrapper div the exact height of the flash movie and set its overflow property to auto. What this does is put the scrolling/key capturing focus on that div instead of the document when you click on the flash piece and play the game. Because the wrapper div is the exact height, there is nothing to scroll and all works well, flash registers the key presses and the screen does not move.
Sample:
<div id="gameWrapper" style="height:400px; overflow:auto"> <div id="flashContent">Flash will load here via SWFObject call. The flash movie is 400px in height and has the param.wmode set to "transparent|opaque"</div> <div>
I was shocked I could not find this solution as easily online as I’d hoped. I did find a few examples of this after I figured it out, but the posts were very difficult to read made a simple solution look terribly difficult.
thx man, you’re a genius. but you got 2 spelling mistakes in your script
cheers
heh, thanks much. Entry edited.
Thanks! It works nicely in IE7, but IE8 doesn’t seem to care about it. Anybody knows how to solve this in IE8?
Not ideal, but you could force the page or pages you need this to work into IE 7 compatibility mode:
http://weblogs.asp.net/joelvarty/archive/2009/03/23/…
Just ran a quick test and it seemed to work. Might not be an ideal solution for some situations though.
Thank you for the solution, i had this problem too!
nice. using this trick plus forcing IE7 compatibility mode (which you can do just in a single iframe) is the only way I have found to combine wmode:transparent with capturing arrow keys. thank you!