May 1, 2001 - Conditional Flash Playing | WebReference

May 1, 2001 - Conditional Flash Playing

Yehuda Shiran May 1, 2001
Conditional Flash Playing
Tips: May 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

The FlashSound JavaScript API's IsPlaying() method checks if the playhead is moving. You can use this method to create innovative sound combinations. For example, you can play a sound track only if the other sound track is mute.

As a reminder, in order to sonify your page, follow this recipe:

flashsound.js in the HEAD section. Download.
  • Create a flashsound object in the
  • HEAD section.
  • Embed your SWF file in the
  • BODY section.
  • Create an anchor tag and set the
  • onmouseover event handler to the TGotoAndPlay() method.

    The left three out of the following four links mimic a typical tape recorder control panel. The right link checks if the playhead is moving along the timeline. Mouse over it and find out the answer to the question "IsPlaying?". The link at the second line plays a scale passage, but only if the tutorial is not playing. We do this conditional playing by checking that the tutorial's IsPlaying() is false. The tutorial's object is mySoundObj1, and the scale passage's object is mySoundObj2. The conditional playing is:

    if (!mySoundObj1.IsPlaying()) mySoundObj2.TGotoAndPlay('/scale-event', 'start')
    Play around with the links. Start the tutorial. Try to play the scale and see that it does not play. Pause the tutorial. Try now to play the scale. See that it does play now. Continue the tutorial. Can you play the scale now?

    Rewind and Play the Tutorial  Pause  Continue  Is Playing?

    Play A Scale

    Here is the source code:

    <SCRIPT SRC="flashsound.js"></SCRIPT>
      var mySoundObj1 = new FlashSound();
      var mySoundObj2 = new FlashSound();
    <P><A HREF="javascript://" 
      onmouseover="mySoundObj1.TGotoAndPlay('/',1)">Rewind and Play the Tutorial</A>
      <A HREF="javascript://" 
      <A HREF="javascript://" 
      <A HREF="javascript://" 
      onmouseover="alert(mySoundObj1.IsPlaying('/'))">Is Playing?</A></P>
      <A HREF="javascript://" 
      onmouseover="if (!mySoundObj1.IsPlaying()) mySoundObj2.TGotoAndPlay('/scale-event', 'start')">Play A Scale</A></P>
      mySoundObj1.autostart = false;

    Notice we assign autostart to false. The reason is that the stream example here was set to autostart upon embedding. We can override the Flash behavior with JavaScript commands.

    Here are links you can use to download flashsound.js, earsonly.swf, and scale.swf:

    Download flashsound.js

    Download earsonly.swf

    Download scale.swf