‘ESPN FLASH detection system’ meets Flash 0

Even in the classy company of bad version detection scripts we've met since we started testing Opera 10, this Flash detection approach stands out. That script goes to great effort to require an update every.single.time Adobe releases another Flash version.

It starts with a bold claim to be the ESPN "Flash detection system", no less:

// Author: Danny Mavromatis
// Version: 2.07.0
// Created: 10/29/2001
// Updated: 3/6/2006
// ESPN.com FLASH detection system
	var f2 = false;
	var f3 = false;
	var f4 = false;
	var f5 = false;
	var f6 = false;
	var f7 = false;
	var f8 = false;
	var f9 = false;

Look at all those variables. What might they be used for? Read on:

var fD = navigator.plugins["Shockwave Flash" + isVersion2].description;
var fV = parseInt(fD.charAt(fD.indexOf(".") - 1));

So, first it extracts one single letter that precedes a dot in the plugin's description of itself. This is presumably the plugin's major version number, you know the 8 in "8.0", the 9 in "9.0", and, um, the 0 in "10.0". Then:

f2 = fV == 2;
f3 = fV == 3;
f4 = fV == 4;
f5 = fV == 5;
f6 = fV == 6;
f7 = fV == 7;
f8 = fV == 8;
f9 = fV == 9;

..it just sets the corresponding "f"-variable to true. If the major version was 8, f8 will be true and so on. A great way to make sure the code will require maintenance – new variables for each new version. And then comes the real gem:

for (var i = 2; i <= mV; i++) {
if (eval("f" + i) == true) aV = i;
}
// alert("version detected: " + aV);

[/code]

Let's see, we just had a variable fV which contained Flash's major version number (or at least its least significant digit) – but this script has severe amnesia. What was that number again? Better use a loop and 8 eval() calls to check the value of that variable. You never know, do you?

Now, dear readers – Mr. Mavromatis clearly needs some help with this code. Obviously, complexity and maintenance requirements are among his design goals. The natural question is whether there are good, non-obvious ways this script could be improved to be more complex and require even more maintenance? Suggestions welcome in comments.

Update: Danny Mavromatis responded in comments and – though he no longer works on the ESPN site – has made sure that the page where we found this problem has been updated. Kudos to Mr. Mavromatis for his quick response and sense of responsibility. I wish more web developers would act this way!

No more personal attacks, please!

34 thoughts on “‘ESPN FLASH detection system’ meets Flash 0

  1. alert(navigator.plugins['Shockwave Flash'+isVersion2].description.split('Shockwave Flash ')[1].split('.')[0]);

    Is that all the script does?Tbh, I think Danny deserves some kind of accolade to have achieved the level of complexity he did. I can't fathom how you could possible go further…. I suppose his boolean variables are quite simple, surely one could devise some large robust function to figure out exactly whether fV really doesn't == 9, just to be one the safe side.

  2. Even if you really want multiple variables and iterate through them I thought we have arrays somewhereโ€ฆI'd say eval() wasn't such a good thing to have in Javascript in the first place.

  3. Anonymous writes:One easy way would be to hardcode exact version numbers. Like:if(fD=='9.0')version=9;if(fD=='9.1rc')version=9;if(fD=='9.1')version=9;if(fD=='9.2-android')version=9;if(fD=='10.0')version=10;if(fD=='10.1')version=10;if(fD=='10.1.2')version=10;

  4. Danny Mavromatis writes:I'm famous! ๐Ÿ˜€ Guys, please keep in mind this code is from 2001 when things were craptastic. I haven't touched the code since and I believe it has since been deprecated. This detection code was what MACROMEDIA provided at the time as well and my version was pretty solid at the time.Cheers!Danny

  5. Anonymous writes:You can't exactly hardcode exact version numbers like that because their are a lot of versions released. You listed just 7 for flash 9 and 10, remember there are 8 others! My own version is 10.2.54.. I'm sure there are many more, especially since there were a few security updates a few months ago.

  6. Danny Mavromatis writes:Yeah, this isn't the modern way to detect for Flash — that's for sure… however, go back to 2001 and this was pretty much the standard… even MACROMEDIA would output this loop when you published a movie with detection. This was originally based on Collin Moock's (http://www.moock.org/webdesign/flash/detection/moockfpi/) Flash Detection System.If I recall correctly, the reason why we looped was to see what version was installed, not if Flash in general was installed. This way, we knew it was Flash 4 vs Flash 5, etc.Digging up what now is 8+ year old code is kind of pointless… I hope this code is no longer in use, if it is, please let me know and I'll get them to update it with the latest "Flash Detection System"!Cheers!Danny

  7. Danny Mavromatis writes:Exactly Clint!Hallvord is taking my old code which is no longer used and if it is, I'd like to know where so I can get it updated with the one we are using today. Again, the way I coded it in 2001, was the standard way to detect Flash versions. His post today was completely irrelevant… In my defense, if I were to write it again today, it would not use this method.Cheers!Danny

  8. if (eval("f" + i) == true) aV = i;

    change to

    if (eval("f" + i) == true) 
    {
       if (i==1) aV = 1;
       if (i==2) aV = 2;
       โ€ฆ
    }
    
  9. Hi Danny and Clint,sure this code looks old (and I'm sure most readers will realise it's from those really dark ages and not hold it against you, Danny ๐Ÿ™‚ ).However Clint, we really don't have time to go surfing file directories on old ESPN content servers to see if there is any old code left to bash. We investigate problems that are reported by Opera users.This very library is still used by http://sports.espn.go.com/broadband/ivp/?ref=splash&id=2996377..which obviously won't work for anyone using Flash 10 with Opera/Firefox/Safari/Chrome.. I don't know how important that page is, but I do know that on January 19th 2009 someone did come across it and was sufficiently annoyed to send us a bug report.(Of course this has nothing to do with Opera, really, it's a problem with Macromedia/ESPN's old JS and Flash – but we did send the bug to our Open The Web people and they have sent ESPN an E-mail.)

  10. Danny Mavromatis writes:Hallvord,I'll personally get this pushed through and updated. Thanks for the heads up!Thanks,Danny

  11. Originally posted by Danny Mavromatis:

    Guys, please keep in mind this code is from 2001 when things were craptastic.

    While I mean no offense by this statement, as far as I can tell the single short line of code I posted in the first comment above would've worked just fine in 2001. So while the argument that things were "craptastic" may hold up with more complex things like XHR, and more modern advanced JS methods, this is fairly basic stuff.Originally posted by Danny Mavromatis:

    his detection code was what MACROMEDIA provided at the time as well

    I've never been a fan of the "everyone else was doing it" argument either.

  12. Anonymous writes:A *good* developer in 2001 would have posted an article like this at *that* time ragging on Macromedia about their boneheaded code, not cut/pasted it into their own library and put their own name on it.

  13. Danny Mavromatis writes:A little background:When I created it, we chose to host our scripts in a global manor, in /insertfiles/javascript/flash.js, however, for whatever reason, the producer that created this page copied the js file into their own folder and didn't follow our standards. As you can see, if they used the original location, the JS file was updated to v3.0.2 in 2006. http://sports.espn.go.com/insertfiles/javascript/flash.js I did improve it and a fix was made to support all versions… we switched to SWFObject when that was released and I moved onto creating the ABC Full Episode Player. Love to hear your critique of version 3.0.2. You guys are ruthless :)Cheers!Danny

  14. Danny Mavromatis writes:Lucideer,While trying to find out more about you, I stumbled upon you blog. Do you know it's completely unreadable and one cannot navigate anywhere… the links are completely non-responsive! How are people suppose to respect you and what you have to say about coding practices when you release code like that on your own personal blog *and* that was written in 2009! Shame on you.Danny

  15. Danny Mavromatis writes:Dear Anonymous,I'm a normal human being and never said I was perfect. Maybe you were born a coding god/genius… awesome – wish I knew your real name and we could chat some more! I, like most, people learn from our mistakes and make improvements like I did when I maintained the codebase. You can see in the later version (3.0.2) the issue was fixed. The producer of the page copied the JS file into their folder which makes it so the library never got updated.I slapped my name on this script because in a huge company like the Walt Disney Company, and at the time, with flash being rare on commercial sites, if people had a bug, they could track me down and I could fix — that even worked today, since I put my name on it, I got notified and bam! I'm getting it fixed. I stand behind my code and products, even 8+ years after. Do you? Plus, we worked closely with Macromedia and this was the recommended detection method at the time… as was Colin Moocks FPI which Macromedia recommended as well all had this issue. Anonymous, I guess I wasn't a JS god like you in 2001.You guys need to ease up on the personal attacks. We are not all perfect and the point is that we all strive to make things as close to perfect as possible. Sometimes we fail other times we succeed. I have put in the request to fix this one page that was not properly referencing the latest version of the detection script. Even if it's fixed, I'm not even sure if the content the flash file is pulling is live anymore.Cheers!Danny

  16. Anonymous writes:To get back to the original question: > The natural question is whether there are good, non-obvious ways this script could be improved to be more complex and require even more maintenance?How about a for-loop evalling the booleans, then parse them to a 1/0, OR them together while shifting the previous value left, and then convert that to a string and report the number of characters.Small javascript quiz: what is maximum version number allowed in this scenario?No code, because I feel morally superior to those writing bad code examples that get copied over the entire web. That, or I'm just lazy ๐Ÿ™‚

  17. Danny: I'm part of Opera's Open the Web team. As hallvord mentioned, our team also contacted ESPN about this, but we generally do not hear a response whenever we make them aware of a website problem. It would be great if you could PM me a contact within ESPN with whom we could forward these issues to and discuss it through. We would *really* appreciate that. There are a few other issues with ESPN.com and related properties that I would like to discuss! Also, Danny, its great that you took the time to respond here and try to fix the issue once you were aware of it. :cheers:

  18. Danny Mavromatis writes:Hi Shwetank, For Sure! I just got your contact info and will get you in contact with the appropriate folks!Talk to you soon!Thanks!Danny

  19. Danny: thanks a lot for getting that page fixed. All users of non-IE browsers appreciate that! Also, it's absolutely brilliant to get a contact within ESPN. Often "Open The Web" efforts fail because the regular customer service staff seem to be light years away from those working on the website itself, so a technical contact really helps ๐Ÿ˜€

  20. Originally posted by Danny Mavromatis:

    Guys, please keep in mind this code is from 2001 when things were craptastic.

    eh :p So back in 2001 people had the excuse of not knowing how to code ?

  21. robmueller writes:…because the regular customer service staff seem to be light years away from those working on the website itself, so a technical contact really helpsI know the feeling. Getting hold of technical people behind a service/website can be a real pain. It would be nice if there was a standard way of getting an email address to a technical person that was only obviously for technical people (eg maybe a HTTP header like ServerAdministrator: ). Still, all a bit late now.

  22. Originally posted by Danny:

    While trying to find out more about you, I stumbled upon you blog. Do you know it's completely unreadable and one cannot navigate anywhere… the links are completely non-responsive! How are people suppose to respect you and what you have to say about coding practices when you release code like that on your own personal blog *and* that was written in 2009! Shame on you.

    Dear Danny,Thank you for the personal attack. I am sorry if I offended you in my post above, it was not my intent (as I believe I stated quite clearly). All I did was state fact. I posted a tiny snippet of code which is vastly simpler and more efficient than what you posted in 2001. I didn't know how to write javascript in 2001, but I was not employed as a web developer for a huge and reputable website either. In fact I have never been. And that is where the line is drawn.My blog is not an enormous site visited by millions, it contains next to no useful information and most importantly NOONE PAID ME TO DEVELOP IT! My blog is a completely unfinished site (which I actually state at the top). Are you honestly comparing a half finished amateur blog design vistited by about 3 people a month to work done by a supposedly professional developer for ESPN?Sorry Danny, but my blog is personal and amateur. Your work for ESPN should be at a professional standard, as would web design work I did for paying clients.

  23. Danny Mavromatis writes:Lucideer,Big companies are not perfect either, I'd say it's amazing things actual get done and work given the amount of people that touch things. As I have stated, the code was updated to a better method and if the producer that created that page used the proper method to call the script from the location that is maintained this wouldn't be a problem. It would have been fixed when I made the change in 2006 that removed that crappy code. The issue here is that the script was copied to another location and other JS code was added to the flash.js (which has nothing to do with my code) … this is bad practice. Things are not as perfect as you think, even for huge companies… look at Vista and even Apple products, they all have some code that the developers are not proud of, however, they fix things and make them better, as I have done. I don't even work for the ESPN group directly anymore, however, I feel like I should make things right. I take ownership of my code and fixed this issue for you guys. No hard feelings… I quite enjoy the criticism, keeps me in check! Keep in touch!Danny

  24. Danny Mavromatis writes:We have updated the code… it should work once the cache is updated (could take a while). Thanks for bringing this to my attention, even if it dragged my name in the mud a bit. :)Cheers!Danny

  25. BAG writes:This is insane. Why not use a regular expression:alert(navigator.plugins['Shockwave Flash'].description.match(/.*?(d+)./)[1]);That will give you the major version number, regardless of how many digits it is. This would've worked just as well in 2001 as it does today. Splitting or substringing may be faster, but more hacky and error-prone. And certainly faster than eval. (*shaking head in disbelief*)The original code is indefensible, Danny. Chalk it up to inexperience if you must, but to claim that things were oh-so-ugly back then that it required that huge pile of declared variables, the loop, and the eval is laughable. I would've LOL'ed at that code in 2001 as much as I do now.

  26. I don't even work for the ESPN group directly anymore, however, I feel like I should make things right. I take ownership of my code and fixed this issue for you guys.[/code]You've certainly earned my respect for that, Danny. Thank you for caring. If only more web developers took responsibility for their past efforts and failures like you've just done!It's frightening to know that a company like Macromedia actually promoted such horrible JavaScript back then. But it's a good example of the loooong way JavaScript has gone towards becoming a well understood and respected programming language. I'm really happy it's not 2001 anymore ๐Ÿ™‚

  27. Danny Mavromatis writes:Update:The cache has updated and I just confirmed the player now works again. The ironic part to all this, this player/templates was last touched in 2008. So this URL is not even a live page/player. It must have been in someone's favorites a this time.I'm now in amazement that this page/player even works today as this is a legacy player…Cheers!Danny

  28. You've certainly earned my respect for that, Danny. Thank you for caring. If only more web developers took responsibility for their past efforts and failures like you've just done!

    Seconded. I wonder how many of the trolls flaming Danny here would show a similar level of professionalism in dealing with a problem with something they don't even work on anymore.

    Kudos, Danny :up:

  29. Wow..at couple of levels.. so you people at Opera read each and every website compatibility report submitted? I keep submitting them whenever someone website irks me enough. Good to know that someone that the other end is reading them all. I figured that just the most commonly reported bugs are dealt with.And nice to see a webdeveloper like Danny who really cares. I wish there were more like him. Opening the Web would be an much easier job.

Leave a reply to anonymous Cancel reply