spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column84


Embedding Sound with Flash, Part IV: Native JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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"]) ?
  navigator.mimeTypes["application/x-shockwave-flash"].
    enabledPlugin : 0;
  if (plugin) {
    var pluginversion = parseInt(plugin.description.
       substring(plugin.description.indexOf(".")-1))
    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:

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

Next: How to embed a SWF

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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