May 6, 2001 - Version-Limited Flash Scripting | WebReference

May 6, 2001 - Version-Limited Flash Scripting

Yehuda Shiran May 6, 2001
Version-Limited Flash Scripting
Tips: May 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Sometimes, writing a version-independent script is too much of an overhead. Instead, you may elect to support all versions higher than a minimum version number. Usually, 80% of your surfers have the most updated player version. So, why bother with older versions? You set the minimum supported version by the setMinPlayer() method. The single argument is the version number.

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.

    Let's verify that indeed setMinPlayer() is doing the job. Since the highest player version number is 5, we would mute the player when we put 6 as the minimum version number. The following three lines of links demonstrate this fact. Set the minimum player version to 5 and get the bottom two lines of link to function as expected. Set the minimum player version to 6 and make the player mute.

    Set Minimum Player to 5  Set Minimum Player to 6

    Rewind and Play the Tutorial  Pause  Continue  Is Playing? Play A Scale

    Here is the source code:

    <HTML>
    <HEAD>
    <SCRIPT SRC="flashsound.js"></SCRIPT>
    <SCRIPT>
      var mySoundObj1 = new FlashSound();
      var mySoundObj2 = new FlashSound();
    </SCRIPT>
    </HEAD>
    <BODY>
    <P><A HREF="javascript://" 
      onmouseover="FlashSound.setMinPlayer(5); 
      alert('Minimum Player Version Set to 5')">
      Set Minimum Player to 5</A>  
      <A HREF="javascript://" 
      onmouseover="FlashSound.setMinPlayer(6);
      alert('Minimum Player Version Set to 6')">
      Set Minimum Player to 6</A></P>
      <A HREF="javascript://" 
      onmouseover="mySoundObj1.TGotoAndPlay('/',1)">Rewind and Play the Tutorial</A>
      <A HREF="javascript://" 
      onmouseover="mySoundObj1.TStopPlay('/')">Pause</A>
      <A HREF="javascript://" 
      onmouseover="mySoundObj1.TPlay('/')">Continue</A>
      <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>
    <SCRIPT>
      mySoundObj1.autostart = false;
      mySoundObj1.embedSWF("earsonly.swf");
      mySoundObj2.embedSWF("scale.swf");
    </SCRIPT>
    </BODY>
    </HTML>

    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