'ESPN FLASH detection system' meets Flash 0
Monday, 29. June 2009, 16:16:30
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);
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!










lucideer # 29. June 2009, 16:36
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.
Chas4 # 29. June 2009, 16:55
Haruka aka Seremel # 29. June 2009, 17:00
I'd say eval() wasn't such a good thing to have in Javascript in the first place.
Anonymous # 29. June 2009, 20:12
I'm famous! :D
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
Anonymous # 29. June 2009, 20:55
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;
Anonymous # 29. June 2009, 21:10
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
Anonymous # 29. June 2009, 21:14
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.
Anonymous # 29. June 2009, 21:54
What a strange post. The Javascript described in this post hasn't been used on ESPN (apparently) since 10/16/2006[1] and doesn't even use the same approach hallvord described.
1: http://a.espncdn.com/insertfiles/javascript/flash.js
Anonymous # 29. June 2009, 22:25
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
hallvors # 29. June 2009, 22:26
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.)
porneL # 29. June 2009, 22:45
if (eval("f" + i) == true) aV = i;change toif (eval("f" + i) == true)
{
if (i==1) aV = 1;
if (i==2) aV = 2;
…
}
Anonymous # 29. June 2009, 23:25
Hallvord,
I'll personally get this pushed through and updated. Thanks for the heads up!
Thanks,
Danny
lucideer # 30. June 2009, 00:17
Originally posted by Danny Mavromatis:
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:
I've never been a fan of the "everyone else was doing it" argument either.
Anonymous # 30. June 2009, 01:26
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.
Anonymous # 30. June 2009, 01:35
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
Anonymous # 30. June 2009, 02:14
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
Anonymous # 30. June 2009, 02:36
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
Anonymous # 30. June 2009, 05:53
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 :)
shwetankdixit # 30. June 2009, 05:53
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.
Anonymous # 30. June 2009, 06:03
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
Haruka aka Seremel # 30. June 2009, 07:28
hallvors # 30. June 2009, 07:51
Anonymous # 30. June 2009, 08:40
You got trolled.
xErath # 30. June 2009, 11:00
Originally posted by Danny Mavromatis:
eh
Anonymous # 30. June 2009, 15:12
...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
I 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: mailto:webmaster@example.com). Still, all a bit late now.
lucideer # 1. July 2009, 02:53
Originally posted by Danny:
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.
Anonymous # 1. July 2009, 03:48
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
Anonymous # 1. July 2009, 03:59
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
Anonymous # 1. July 2009, 13:46
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.
hallvors # 1. July 2009, 13:57
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
Anonymous # 1. July 2009, 22:05
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
nickfitz # 4. July 2009, 17:59
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
Indyan # 22. July 2009, 16:08
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.
Chas4 # 22. July 2009, 16:19
http://my.opera.com/community/forums/forum.dml?id=29
I would guess Opera gets a lot of reports, that they have to look thru
One other ESPN site I wonder about is ESPN360.com