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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Top 10 Threats to Wireless Security · Poll: UC Uptake on the Rise · Review: Fluke AirCheck Wi-Fi Tester 1.0