spacer

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

home / experts / javascript / column85


Embedding Movies with Flash, Part I: Basic Methods

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

Embedding a Flash Movie

In Column 84 we used the JavaScript include file, flashsoundcheck.js, to take care of all the tiny details of embedding the Flash player, checking for browser compatibility, and verifying that the version of the installed Flash player is equal or higher than what we require. We explained in detail the content and structure of this file in Column 84.

We've extended the JavaScript include file to support movies, and called the new file flashmoviecheck.js. The JavaScript file flashmoviecheck.js does exactly this, and other stuff. It is different than the sound-based flashsoundcheck.js in that the dimensions should be adjusted to the movie size. When you embed sound objects, you size the object as small as possible. In Internet Explorer the minimum is 1 pixel by 1 pixel. In Netscape Navigator the minimum size is 1 pixel by 2 pixels. Since we want to support movies of any size, we opted to use the 100% value for both WIDTH and HEIGHT. We also changed the default quality to "high," and removed two parameters from the Netscape Navigator section (swLiveConnect and wmode). Here is the code:

winIEpass = ((navigator.appName.indexOf("Microsoft") != -1)
   && (navigator.appVersion.indexOf("Windows") != -1)) &&
  (parseFloat(navigator.appVersion) >= 4) ? true : false;

NNpass = ((navigator.appName == "Netscape") &&
  (navigator.userAgent.indexOf("Mozilla") != -1) &&
  (parseFloat(navigator.appVersion) >= 4) &&
  (navigator.javaEnabled())) ? true : false;

  supportedBrowser = (winIEpass || NNpass) ? true : false;

// check for Flash Plug-in in Mac or Win Navigator.
// Get plug-in version.

minPlayer = 4;
var mySwf;

function Flash_checkForPlugIn() {
  var plugin = (navigator.mimeTypes &&
  navigator.mimeTypes["application/x-shockwave-flash"]) ?
  navigator.mimeTypes["application/x-shockwave-flash"]
    .enabledPlugin : 0;
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
  if (plugin) {
    var pluginversion = parseInt(plugin.description
     .substring(plugin.description.indexOf(".")-1))
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
    if(pluginversion >= minPlayer) {return true;}
  }
  return false;
}

// vbscript check for Flash ActiveX control in windows IE
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' +
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
    'If hasPlayer = true Then Exit Do' + '\n' +
    'playerversion = playerversion - 1' + '\n' +
    'Loop' + '\n' +
    'Flash_checkForActiveX = hasPlayer' + '\n' +
    'End Function' + '\n' +
    '<\/script>'
  );
}

function Flash_checkForMinPlayer() {
  if(!supportedBrowser) return false;
  if(NNpass) return (Flash_checkForPlugIn());
  if(winIEpass) return (Flash_checkForActiveX());
}

function Flash_embedSWF(srcURL, swfbgColor) {

  if (!Flash_checkForMinPlayer()) return;

  var defaultColor = (document.bgColor != null) ?
    document.bgColor : "#ffffff";
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
  var bgcolor = (swfbgColor != null) ? swfbgColor 
  : defaultColor;
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
  document.writeln(
    '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-
    444553540000"' +
  // (The two lines above should be joined as one line.
  // They have been split for formatting purposes.)
'codebase="http:
  //active.macromedia.com/flash2/cabs/swflash.cab#
  version=4,0,0,0"' +
  // (The three lines above should be joined as one line.
  // They have been split for formatting purposes.)
    'ID="sonify" WIDTH="100%" HEIGHT="100%">' +
    '<PARAM NAME="movie" VALUE="' + srcURL + '">' +
    '<PARAM NAME="quality" VALUE="high">' +
    '<PARAM NAME="wmode" VALUE="transparent">'+
    '<PARAM NAME="autostart" VALUE="false">'+
    '<PARAM NAME="bgcolor" VALUE=' + bgcolor + '>' +
    '<embed src="' + srcURL + '" quality="high"'
    + 'bgcolor="' + bgcolor + '"' + 'width="100%"
    height="100%"' + 'type="application/x-shockwave-flash"
    NAME="sonify"' + 'pluginspage="http:
 //www.macromedia.com/shockwave/download/index.cgi?
 P1_Prod_Version=ShockwaveFlash"></embed></OBJECT>');
  // (The three lines above should be joined as one line.
  // They have been split for formatting purposes.)

  window.document.sonify.Rewind();
}

function sonified_flash(myFrame){
  if(!Flash_checkForMinPlayer()) {return;}

  mySwf = window.document.sonify;
  if (mySwf.PercentLoaded()<100) return

  mySwf.GotoFrame(myFrame);
  mySwf.GotoFrame(0);
}

Next: How to play a Flash movie

http://www.internet.com

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


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

URL: http://www.webreference.com/js/column85/2.html