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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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>'
  );
}


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business