views:

631

answers:

2

Hi. I have a flex app that I want to hide in a div until the user clicks a link or element of some type. I've noticed that embedding the swf in a div with style display:none does not actually hide the swf, so how would I go about accomplishing this?

The goal is to have the flex app loading in the background while the user does other things. Thanks.

+1  A: 

Try setting the following wmode to your flash object, and use visibility: hidden; as well.

<param name="wmode" value="opaque" />
<embed ... wmode="opaque" ... />

By default, flash basically overlays a window over your content, which is:

  1. Has a greater z-index than anything on your page
  2. Doesn't inherit display from its parent (setting display: none; visibility: hidden; to the <object> tag will work).

By setting wmode to opaque, it basically tells flash to treat your <object> as a normal DOM tag, which responds to normal inheritance and z-index rules. It has a very small performance cost.

Also, note that some browsers will not load the object until it is displayed.

Andrew Moore
This does not work in IE8, IE6, or Opera. display:none still fails to hide the embedded swf.I need this to work in all browsers, essentially. (Opera, chrome, IE6/7/8, Firefox3/3.5/3.5.1, Safari 3+)
Stefan Kendall
**@iftrue:** updated my post for more information. You may always try setting `display: none; visibility: hidden;` on your object tag itself, but I have used `wmode` without any problems in the named browsers in the past.
Andrew Moore
As it turns out, there was a special flash deployment process which was hidden by multiple javascript includes. Using wmode in the correct place worked swimmingly :).
Stefan Kendall
**@iftrue:** In which case you might want to consider changing your accepted answer.
Andrew Moore
+1  A: 

I usually just force the height/width of the container to 1 by 1 px...

<div style="height:1px; width:1px;" >... flash goes here ...<div>

Then, when I need the flash, I will re-set the height/width as appropriate. Note, you may want to put this into a parent container if you want to just reset the hw to "100%" which will bind to a parent div, with a "position:relative; height:?px; width:?px" setting.

Tracker1