May 11, 2001 - Checking for Flash on Win IE | WebReference

May 11, 2001 - Checking for Flash on Win IE

Yehuda Shiran May 11, 2001
Checking for Flash on Win IE
Tips: May 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

In some of your applications you may need to use Flash Audio and JavaScript directly, without any prepackaged APIs such as FlashSound JavaScript API. You will enjoy more features, methods, and properties, but you'll have to take care of all the tiny details that are taken for granted when using FlashSound API.

One of these tiny details is checking that the Flash player is installed. On a Win Internet Explorer system, Flash is implemented by an ActiveX control. The easiest way to check for Flash on such a system is by VBScript. Here is the code:

<SCRIPT LANGUAGE=VBScript>
Function Flash_checkForActiveX
  Dim hasPlayer, playerversion, minVersion
  minVersion = 4
  hasPlayer = false
  playerversion = 10
  Do While playerversion >= minVersion
   On Error Resume Next
   hasPlayer = (IsObject(CreateObject(
     "ShockwaveFlash.ShockwaveFlash." & playerversion & "")))
   If hasPlayer = true Then Exit Do
   playerversion = playerversion - 1
  Loop
  Flash_checkForActiveX = hasPlayer
End Function
</SCRIPT>

And here is the conditional version of the same script. It checks first that the browser is supported, as well as that the system is WIN IE. Only then it writes our the VBScript to check that the player is installed and its version is supported. Here is the code:

if(supportedBrowser && winIEpass) {
  document.write(
    '<script language=VBScript>' + '\n' +
    'Function Flash_checkForActiveX()' + '\n' +
    'Dim hasPlayer, playerversion' + '\n' +
    'hasPlayer = false' + '\n' +
    'playerversion = 10' + '\n' +
    'Do While playerversion >= minPlayer' + '\n' +
    'On Error Resume Next' + '\n' +
    'hasPlayer =  (IsObject(CreateObject(\
        "ShockwaveFlash.ShockwaveFlash.\" & playerversion & \"\")))' + '\n' +
    'If hasPlayer = true Then Exit Do' + '\n' +
    'playerversion = playerversion - 1' + '\n' +
    'Loop' + '\n' +
    'Flash_checkForActiveX = hasPlayer' + '\n' +
    'End Function' + '\n' +
    '<\/script>'
  );
}