Embedding Sound with Flash, Part IV: Native JavaScript: Checking the Flash Player - Doc JavaScript | WebReference

Embedding Sound with Flash, Part IV: Native JavaScript: Checking the Flash Player - Doc JavaScript

Embedding Sound with Flash, Part IV: Native JavaScript

Checking the Flash Player

Before embedding your Flash track, check that the Flash plug-in is installed in Mac or Windows Navigator. The following function, Flash_checkForPlugIn(), does exactly that. It checks that the mimeTypes object exists, that one of the MIME types is flash, and that its relevant plug-in is enabled. The function also extracts the plug-in version, and checks that it is higher than the default minimum player version. The default minimum player version is set as a global variable before calling Flash_checkForPlugIn(). Here is the function in full, preceded by the global variable assignment of minPlayer:

function Flash_checkForPlugIn() {
  var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ?
    enabledPlugin : 0;
  if (plugin) {
    var pluginversion = parseInt(plugin.description.
    if(pluginversion >= minPlayer) {return true;}
  return false;

On a Win Internet Explorer system, Flash is implemented as an ActiveX control. The easiest way to check for Flash on such a system is with VBScript. Here is the code:

Function Flash_checkForActiveX
  Dim hasPlayer, playerversion, minVersion
  minVersion = 4
  hasPlayer = false
  playerversion = 10
  Do While playerversion >= minVersion
   On Error Resume Next
   hasPlayer = (IsObject(CreateObject(
     & playerversion & "")))
   If hasPlayer = true Then Exit Do
   playerversion = playerversion - 1
  Flash_checkForActiveX = hasPlayer
End Function

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 does it write the VBScript to check that the player is installed and its version is supported. Here is the code:

if(supportedBrowser && winIEpass) {
    '<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(\
      & playerversion & \"\")))' + '\n' +
    'If hasPlayer = true Then Exit Do' + '\n' +
    'playerversion = playerversion - 1' + '\n' +
    'Loop' + '\n' +
    'Flash_checkForActiveX = hasPlayer' + '\n' +
    'End Function' + '\n' +

Next: How to embed a SWF


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: May 21, 2001
Revised: May 21, 2001

URL: http://www.webreference.com/js/column84/3.html