April 9, 2001 - Fading a Flash Sound | WebReference

April 9, 2001 - Fading a Flash Sound

Yehuda Shiran April 9, 2001
Fading a Flash Sound
Tips: April 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

The SWF format supports fading a sound track before a complete stop. In order to sonify your page, follow this recipe:
  • Make sure you have the Flash player. 96% of the surfing population already has it. Download.
  • Include
flashsound.js in the HEAD section.
  • Create a flashsound object in the
  • HEAD section.
  • Embed your swf file in the
  • BODY section.
  • Create an anchor tag and set the
  • onclick event handler to the TGotoAndPlay() method.

    Here is an example that plays a funky music which you can fade and stop:

    Play the funky music

    Fade and stop the funky music

    Here is the source code:

    <HTML>
    <HEAD>
      <SCRIPT SRC="flashsound.js"></SCRIPT>
      <SCRIPT>
        var mySoundObj = new FlashSound();
      </SCRIPT>
    </HEAD>
    <BODY>
    <P><A HREF="javascript://" onclick="mySoundObj.TGotoAndPlay('/fistycuffs', 'start')">Play the funky music</A>
    <P><A HREF="javascript://" onclick="mySoundObj.TGotoAndPlay('/fistycuffs', 'fadetostop')">Fade and stop the funky music</A>
    <SCRIPT>
      mySoundObj.embedSWF("funkymusic.swf");
    </SCRIPT>
    </BODY>
    </HTML>

    Here are links you can use to download flashsound.js and funkymusic.swf:

    Download flashsound.js

    Download funkymusic.swf