<h1><ahref="http://www.schillmania.com/projects/soundmanager2/">SoundManager 2</a>: Flashblock / "click to flash" handling demos</h1>
<h3>Show SWF inline, wait indefinitely for load (click-to-run or whitelist)</h3>
<pclass="note">You can run this demo with <ahref="#flash8"onclick="window.location.replace(this.href);window.location.reload()">Flash 8</a> (default), <ahref="#flash9"onclick="window.location.replace(this.href);window.location.reload()">Flash 9</a> (normal mode) or <ahref="#flash9-highperformance"onclick="window.location.replace(this.href);window.location.reload()">Flash 9 + highPerformance mode</a> (higher JS callback frequency).</p>
<h4>Where (and when) to show the SWF</h4>
<p>To handle potential flash block cases, put <code><div id="sm2-container"></div></code> in your markup where you'd like the SWF to appear in those cases. If not specified, SM2 will create and append the <code>#sm2-container</code> node to the document when it starts.</p>
<p>When <code>soundManager.useFlashBlock</code> is true, SM2 will not apply styles (eg. <code>style.position.left</code>) directly to the flash; rather, it will assign CSS classes and you can handle it as you choose. Take a look at <ahref="#flashblock-css">the related CSS</a> file you will also need if you turn this feature on.</p>
<h4>Handling failed start-up cases</h4>
<p>In the blocked/failed start-up case, <code>#sm2-container</code> will have a class name of <code>swf_timedout</code> applied to it.</p>
<p>SM2 will start its init process, and will fire <code>onready()</code>, <code>onload()</code> and <code>onerror()</code> handlers accordingly. Keep in mind that while <code>onerror()</code> may fire at first, it may be preceded by a successful <code>onload()</code> if the user first loads the page and then later unblocks the flash movie.</p>
<p>Note that flash blockers may not run when viewing offline (via <code>file://</code>) content, so try viewing this demo online. For FlashBlock (under Firefox), you can also go to <code>about:config</code> using your address bar and change the value of <code>flashblock.blockLocal</code> to test while offline.</p>
<h3>Flash Block Example</h3>
<p>Here, Flash is appended by SM2 to the <code>#sm2-container</code> DIV and after a failed start attempt (if you have a blocker active), will have a <code>swf_timedout</code> class appended.</p>
<p>The SWF uses <code>position:absolute</code> and negative left/top values so as not to affect the normal page layout, but shifts to <code>left:auto;top:auto</code> (effectively left/top:0) in the blocked case, and becomes visible to the user. On a successful unblock, the movie goes back to left/top:-9999em and is hidden from view.</p>
<p>When <code>soundManager.useFlashBlock</code> is enabled, CSS is applied to <code>#sm2-container</code> depending on the progress of SM2's start-up.</p>
<p>This page + demos use the rules below, fully-defined and commented in <ahref="flashblock.css">flashblock.css</a>. Use it as a base for your own SM2 + flash block implementations.</p>
<preclass="block"><code>#sm2-container {
<span><span>/* Initial state: position:absolute/off-screen, or left/top:0 */</span></span>
}
#sm2-container.swf_timedout {
<span><span>/* Didn't load before time-out, show to user.
Maybe highlight on-screen, red border, etc..? */</span></span>
}
#sm2-container.swf_unblocked {
<span><span>/* Applied if movie loads successfully
(flash started, so move off-screen etc.) */</span></span>
}
#sm2-container.swf_error {
<span><span>/* "Fatal" error case: SWF loaded,
but SM2 was unable to start for some reason.
(Flash security or other error case.) */</span></span>
}
#sm2-container.high_performance {
<span><span>/* Additional modifier for "high performance" mode
should apply position:fixed and left/bottom 0 to stay on-screen
at all times (better flash performance) */</span></span>
}
#sm2-container.flash_debug {
<span><span>/* Additional modifier for flash debug output mode
should use width/height 100% so you can read debug messages */</span></span>