Question

Flash detection code not working in IE

Asked by: Serberus

I've moved the flash detection script that is generated by Flash MX into a function and then called this function onLoad. I've tested the code with several alert boxes. In Internet Explorer the line "var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;" returns 0, this used to work when not in a function. This works fine in Mozilla 1.4

The code:

<script language="Javascript1.1">
<!--
function write_flash(srcFlash, srcStatic, fshHeight, fshWidth, mapName, loop)
{
      var MM_contentVersion = 6;
      var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

      if (plugin) {
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i) {
                  if (isNaN(parseInt(words[i])))
                        continue;
                  var MM_PluginVersion = words[i];
            }
            var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
      } else if ((navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.appVersion.indexOf("Win") != -1)) {
            document.write('<scr' + 'ipt language="VBScript"\>');
            document.write('on error resume next\n');
            document.write('MM_FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))');
            document.write('</scr' + 'ipt\>');
      }

      if (loop == true) {
            loopParam = '<param name="loop" value="true">';
            loopCode = '';
      } else {
            loopParam = '<param name="loop" value="false">';
            loopCode = 'loop="false"';
      }

      if (MM_FlashCanPlay) {
            document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
            document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
            document.write(' id="'+mapName+'" width="'+fshWidth+'" height="'+fshHeight+'">');
            document.write('<param name="movie" value="'+srcFlash+'"><param name="menu" value="false"><param name="quality" value="best">');
            document.write('<param name="scale" value="noscale"><param name="bgcolor" value="#000000">'+loopParam);
            document.write('<embed src="'+srcFlash+'" menu="false" quality="best"'+loopCode+' scale="noscale" bgcolor=#000000 ');
            document.write(' swLiveConnect="false" width="'+fshWidth+'" height="'+fshHeight+'" name="'+mapName+'"');
            document.write(' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
            document.write('</embed>');
            document.write('</object>');
      } else {
            document.write('<img src="'+srcStatic+'" width="'+fshWidth+'" height="'+fshHeight+'" usemap="#'+mapName+'" border="0">');
      }
}
//-->
</script>

further down the page I call the function with:

<map name="eyes"></map><script language="JavaScript1.1">document.onLoad = write_flash("_flash/eyes.swf", "_images/kmx_eyes.jpg", "91", "203", "eyes", true)</script><noscript><img src="_images/kmx_eyes.jpg" width="203" height="91" usemap="#eyes" border="0"></noscript>

This is weird as all I did was move it inside a function, first without any modification, and it stopped working. I modified it later thinking I could work the problem out but for some reason the "var plugin =..." is not working now in IE.

Any help appreciated. Sorry about the points on this question I've only just registered, will have to earn a few ;)

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-09-23 at 03:35:39ID20746115
Tags

ie

,

mm_flashcanplay

,

write_flash

Topic

JavaScript

Participating Experts
3
Points
125
Comments
11

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. how to detect plugins in MSIE
    how to detect plugins in MSIE meanign how to find out which plugins are available on the system using java or javascript or vbscript ?
  2. object classid="clsid:
    i'm looking at some html calling a flash movie: <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.ca b#version=4,0,2,0" width="626" height="200 <para...
  3. Alternate Image for a Flash Movie
    How can you have an alternate image for a flash movie, so that if a viewer to your website doesn't have flash installed, it will display an alternate image instead? Thank You Brian

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ryancysPosted on 2003-09-23 at 03:57:13ID: 9411847

Try add these code:

detector.js:

var requiredVersion = 5;   // Version the user needs to view site (max 6, min 2)
var useRedirect = false;    // Flag indicating whether or not to load a separate
                           // page based on detection results. Set to true to
                           // load a separate page. Set to false to embed the
                           // movie or alternate html directly into this page.
                           
// *************
// Everything below this point is internal until after the BODY tag.
// Do not modify! Proceed to the BODY tag for further instructions.
// *************

// System globals
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var maxVersion = 6;             // highest version we can actually detect
var actualVersion = 0;          // version the user really has
var hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;            // the version of javascript supported


// Check the browser
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

jsVersion = 1.1;

if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


function detectFlash() {  
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {
   
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
 
  // Loop through all versions we're checking, and
  // set actualVersion to highest detected version.
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
 
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  

  if (actualVersion >= requiredVersion) {
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace(flashPage);  
      } else {
        window.location = flashPage;
      }
    }
      
          hasRightVersion = true;                
  } else {  
    // The user doesn't have a new enough version.
    // If the redirection option is on, load the appropriate alternate page.
    if (useRedirect) {
      // Do the same .replace() call only if js1.1+ is available.
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}


detectFlash();


then in your page, try add:

<script language="Javascript1.2" src="../js/detector.js"></script>


<Script language = "Javascript">

if (!useRedirect) {    // if dynamic embedding is turned on
  if(hasRightVersion) {  // if we've detected an acceptable version
    var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'WIDTH="282" HEIGHT="174"'
    + 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<PARAM NAME="MOVIE" VALUE="images/side_company.swf">'
    + '<PARAM NAME="PLAY" VALUE="true">'
    + '<PARAM NAME="LOOP" VALUE="false">'
    + '<PARAM NAME="QUALITY" VALUE="high">'
    + '<PARAM NAME="MENU" VALUE="false">'
    + '<EMBED SRC="images/play.swf"'
    + 'WIDTH="282" HEIGHT="174"'
    + 'PLAY="true"'
    + 'LOOP="false"'
    + 'QUALITY="high"'
    + 'MENU="false"'
    + 'TYPE="application/x-shockwave-flash"'
    + 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    + '</EMBED>'
    + '</OBJECT>';

    document.write(oeTags);   // embed the flash movie
  } else {
    var alternateContent = '<IMG SRC="images/pix_com.jpg">'
//      + '<BR>any desired alternate html code goes here';

    document.write(alternateContent);  // insert non-flash content
  }
}
</script>

 

by: SerberusPosted on 2003-09-23 at 04:16:31ID: 9411942

The key reason I moved the code to a function and called it onLoad was so the flash is displayed once the page is loaded. My current problem is if the flash loads first, the animation starts before the surrounding graphics have loaded. The method you've given me (although it appears to have a more robust and comprehensive detection function) still requires it's own code in the body for each flash movie (more than 1 movie per page and you've duplicated the code) and is loaded as soon as the browser parses the page.

Is there no explanation as to why the "var plugin = ...." ceases to work when moved into a function?

Cheers for the feedback so far...

 

by: jonnalPosted on 2003-09-23 at 08:57:17ID: 9414049

hi

put an alert() at the start of your function to make sure its been called

 

by: SerberusPosted on 2003-09-23 at 09:32:04ID: 9414337

Cheers for the tip. I've already done this however. That's how I tracked down that it's the first line "var plugin = ..." that is coming back as 0 in IE, and consequently document.write'ing the static gif instead of the swf object code.

This code worked fine when it was embedded straight into the page and not contained within a function. wEiRD

 

by: jonnalPosted on 2003-09-23 at 10:10:42ID: 9414634

oh well anyway

your function is over-writing the page, once you call doument.write after the page is loaded
the old document is cleared.

the VB hook has to in the page as it loads

 

by: SerberusPosted on 2003-09-23 at 16:20:35ID: 9416987

It's appending to the page, it document.write's the code where I've called it I presume, that's what it appears to be doing.

This is up the top of the document (will move to head):

<script language="Javascript1.1">
<!--
function write_flash(srcFlash, srcStatic, fshHeight, fshWidth, mapName, loop)
{
      var MM_contentVersion = 6;
      var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

      if (plugin) {
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i) {
                  if (isNaN(parseInt(words[i])))
                        continue;
                  var MM_PluginVersion = words[i];
            }
            var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
      } else if ((navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.appVersion.indexOf("Win") != -1)) {
            document.write('<scr' + 'ipt language="VBScript"\>');
            document.write('on error resume next\n');
            document.write('MM_FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))');
            document.write('</scr' + 'ipt\>');
      }

      if (loop == true) {
            loopParam = '<param name="loop" value="true">';
            loopCode = '';
      } else {
            loopParam = '<param name="loop" value="false">';
            loopCode = 'loop="false"';
      }

      if (MM_FlashCanPlay) {
            document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
            document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
            document.write(' id="'+mapName+'" width="'+fshWidth+'" height="'+fshHeight+'">');
            document.write('<param name="movie" value="'+srcFlash+'"><param name="menu" value="false"><param name="quality" value="best">');
            document.write('<param name="scale" value="noscale"><param name="bgcolor" value="#000000">'+loopParam);
            document.write('<embed src="'+srcFlash+'" menu="false" quality="best"'+loopCode+' scale="noscale" bgcolor=#000000 ');
            document.write(' swLiveConnect="false" width="'+fshWidth+'" height="'+fshHeight+'" name="'+mapName+'"');
            document.write(' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">');
            document.write('</embed>');
            document.write('</object>');
      } else {
            document.write('<img src="'+srcStatic+'" width="'+fshWidth+'" height="'+fshHeight+'" usemap="#'+mapName+'" border="0">');
      }
}
//-->
</script>

This is further down the body where I want the flash to be displayed:

<script language="JavaScript1.1">document.onLoad = write_flash("_flash/eyes.swf", "_images/kmx_eyes.jpg", "91", "203", "eyes", true)</script><noscript><img src="_images/kmx_eyes.jpg" width="203" height="91" usemap="#eyes" border="0"></noscript>

 

by: jonnalPosted on 2003-09-23 at 19:11:14ID: 9417647

hi again

your function is been called after the page finishes loading..... by the onLoad event

document.onLoad = write_flash("_flash/eyes.swf", "_images/kmx_eyes.jpg", "91", "203", "eyes", true)

it dos'nt matter where you place the call or the code

 

by: SerberusPosted on 2003-09-24 at 01:08:11ID: 9419035

OK. Is there another method to displaying the flash once the page has loaded?

Can I pause the movie at the start then use Javascript to communicate with the swf file and tell it to start playing?

 

by: jonnalPosted on 2003-09-24 at 09:22:46ID: 9422030

hi

yes, load it in the normal way
add a stop(); to the swf at frame(1)


in the body tag do this...<body onload="gogo()">

which should start the movie playing
here I'm using "eyes" as the id of swf

function gogo(){

var IExplorer = navigator.appName.indexOf("Microsoft") != -1;
var mc = IExplorer ? window.eyes: window.document.eyes;
    mc.Play();
  //  mc.Zoom(0);
}

 

by: jaysolomonPosted on 2004-02-02 at 12:28:39ID: 10255496

No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jonnal {http:#9422030}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...