Embedding Sound with Flash, Part I: The Basics: Examples for Page Sonification - Doc JavaScript | WebReference

Embedding Sound with Flash, Part I: The Basics: Examples for Page Sonification - Doc JavaScript


Embedding Sound with Flash, Part I: The Basics

Examples for Page Sonification

In our first example, let's sound a beam scan. The frame name is "/beamscan" and it has two labels: "start" and "stop". First, try it (the track's length is a couple of seconds, so stop it immediately if you want to catch it before the end of the track):

Play the beam scan

Stop the beam scan

We have a few examples on this page. Since you can associate a single SWF file with each FlashSound object, we need to create a FlashSound object for each SWF file. Here is the code for the example above:


<HEAD>
  <SCRIPT SRC="flashsound.js"></SCRIPT>
  <SCRIPT>
    var mySoundObj1 = new FlashSound();
  </SCRIPT>
</HEAD>
<BODY>
<P><A HREF="javascript://"
  onclick="mySoundObj1.TGotoAndPlay('/beamscan',
  'start')">Play the beam scan</A>
<P><A HREF="javascript://"
  onclick="mySoundObj1.TGotoAndPlay('/beamscan',
  'stop')">Stop the beam scan</A>
<SCRIPT>
  mySoundObj1.embedSWF("interactivesound.swf");
</SCRIPT>
</BODY>
</HTML>

Our next example is taken from the kung fu martial art. The SWF file "hyperkungfu_32.swf" includes a dozen different sound bits associated with kung fu. In the example below the sound bits are called after their lables in the SWF file. Try them out:

Play the b1 sound

Play the k1 sound

Play the k2 sound

Play the k3 sound

Play the p2 sound

Play the p3 sound

Play the p4 sound

Play the p5 sound

Play the v2 sound

Play the v3 sound

Play the w1 sound

Play the w2 sound

We use the object mySoundObj2 for this example. Here is the source code for the first two links:

<HTML>
<HEAD>
  <SCRIPT SRC="flashsound.js"></SCRIPT>
  <SCRIPT>
    var mySoundObj2 = new FlashSound();
  </SCRIPT>
</HEAD>
<BODY>
<P><A HREF="javascript://"
  onclick="mySoundObj2.TGotoAndPlay('/b1',
  'start')">Play the b1 sound</A>
<P><A HREF="javascript://"
  onclick="mySoundObj2.TGotoAndPlay('/k1',
  'start')">Play the k1 sound</A>
<SCRIPT>
  mySoundObj2.embedSWF("hyperkungfu_32.swf");
</SCRIPT>
</BODY>
</HTML>

Our third example shows Flash's ability to fade and stop. Here is a link that start a funky music and another one that fades and stops it:

Play the funky music

Fade and stop the funky music

We use the mySoundObj3 object for this example. This is the source code:

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

Next: A Final Word

http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: April 9, 2001
Revised: April 9, 2001

URL: http://www.webreference.com/js/column81/5.html