<metaname="description"content="How to load soundmanager2.js on-the-fly using JavaScript, and start it dynamically after window.load() has already fired using beginDelayedInit()."/>
<styletype="text/css">
#soundmanager-debug {
/* SM2 debug container (optional, use or customize this as you like - makes in-browser debug output more useable) */
<p>It's good to let users see the flash component of SM2, so those with flash blockers can unblock it and allow SM2 to start. For more info on this, see the <ahref="../flashblock/"title="SoundManager 2 with Flash block handling"onclick="if (!document.domain) this.href=this.href+'index.html'">Flashblock</a> example.</p>
<h2>Making SM2 wait for window.onload()</h2>
<p>If you prefer to have the library wait for window.onload() before calling soundManager.onload()/onerror() methods, you can modify SM2's "waitForWindowLoad" property:</p>
<h2style="margin-top:1em">Preventing auto-init using SM2_DEFER</h2>
<p>If you want to completely defer the normal start-up of SM2 and call the SoundManager() constructor yourself, you can declare an SM2_DEFER global and set it to true.</p>
<pre><code>window.SM2_DEFER = true;
<span>// some time later, manually start SM2...</span>
soundManager.beginDelayedInit(); <span>// ensure SM2 begins its init process, in the event dom ready / window.load() have already passed</span></code></pre>
<p>SoundManager 2 will write to a debug <div> element or a javascript console if available, by default. To disable it, simply set the relevant property to false:</p>
<code>soundManager.debugMode = false;</code>
<p>To see related configuration code, refer to the source of this page which basically does all of the above "for real."</p>
<h2>Troubleshooting</h2>
<p>If SM2 is failing to start and throwing errors due to flash security, timeouts or other issues, check out the <ahref="../../doc/getstarted/#troubleshooting"title="SoundManager 2 troubleshooting tool"onclick="if (!document.domain) this.href=this.href.replace(/\#/,'index.html#')">troubleshooting tool</a> which can help you fix things.</p>
<h2>No-debug, compressed version of soundmanager2.js</h2>
<p>Once development is finished, you can also use the "minified" (60% smaller) version of SM2, which has debug output and comments removed for you: <ahref="../../script/soundmanager2-nodebug-jsmin.js">soundmanager2-nodebug-jsmin.js</a>. If you can, serve this with gzip compression for even greater bandwidth savings!</p>