Express Installer Utility

May 15th, 2008

When doing the home page for Heavy.com we came across a “special” bug with our Flash detection script. Apparently some people who were running FireFox and Flash Player 9.0.xx+ were not able to make it through the detection script. The issue seemed to be that the browser would throw the wrong player version to JS and JS would fail to load the site (like it should do by prompting you to upgrade) but this was happening to people who had the correct version of the player. We caught this bug in QA before launching the site but here is the class I used to get around this problem.

package {
        import flash.events.EventDispatcher;
        import flash.system.Capabilities;       

        dynamic public class ExpressInstallerUtility extends EventDispatcher {

                public static const INIT : String = “init”;
                private static var __instance : ExpressInstallerUtility;
                private var eventDispatcher : EventDispatcher;

                public function ExpressInstallerUtility(enforcer : SingletonEnforcer) {
                        eventDispatcher = new EventDispatcher();
                }

                public static function get instance() : ExpressInstallerUtility {
                        if(ExpressInstallerUtility.__instance == null) {
                                ExpressInstallerUtility.__instance = new ExpressInstallerUtility(new SingletonEnforcer());
                        }
                        return ExpressInstallerUtility.__instance;
                }

                /**
                 * Returns the full Player version from the Capabilities class.
                 * @return String: MAC 9,0,115,0
                 */

                public function get player_version() : String {
                        return Capabilities.version;
                }

                /**
                 * Returns the OS.
                 * @return String: MAC
                 */

                public function get os() : String {
                        return player_version.split(” “)[0];
                }

                /**
                 * Returns the version.
                 * @return String: 9,0,115,0
                 */

                public function get version() : String {
                        return player_version.split(” “)[1];
                }

                /**
                 * Returns version as an Array.
                 * @return Array: version
                 */

                public function get version_array() : Array {
                        return version.split(“,”);
                }

                /**
                 * Compares min version to the current player’s version.
                 * @param min_version:String = "9,0,115,0"
                 */

                public function has_version(min_version : String) : Boolean {
                        var current_version : Array = version_array;
                        var min_version_array : Array = min_version.split(“,”);
                        return compare(current_version, min_version_array);
                }

                /**
                 * Compares two versions of the player and returns if the current player is ok.
                 * @param current_version: Array of the player version.
                 * @param min_version: Array of the min version to test for.
                 * @return Boolean: True = Good to go, False = current player is to low
                 */

                internal function compare(current_version : Array, min_version : Array) : Boolean {
                        var n1 : Number = 0;
                        var n2 : Number = 0;
                        var pad : Array = [10000000000, 100000, 10, 0];
                        for (var i : Number = current_version.length - 1;i >= 0; i–) {
                                n1 += parseInt(current_version[i]) * pad[i];
                        }
                        for (var j : Number = min_version.length - 1;j >= 0; j–) {
                                n2 += parseInt(min_version[j]) * pad[j];
                        }
                        return n1 >= n2;
                }
        }
}

class SingletonEnforcer {
}

There is nothing really special about this class. It basically adds some new functions to allow you to check for a “min” version vs the installed version. Why use this? Well the way adobe has you do a version detection is to use an AS 1 version 7 (ish) swf to do the detection. Since JS got hung up on the browsers that had the mismatched version of 9.0.xx we decided to add the check into the main app and only call the express install if the app said we had to.

So what happens is that if JS detects that you have version 9.X + it goes right into the app. Anything below is handled the old way with express install and JS. So once you are in the app I use something like this to make sure you have everything you need to run the homepage swf.

var min_version:String = “9,0,115″; // This should come in from flash vars

if(ExpressInstallerUtility.instance.has_version(min_version)) {
                // Start App
        }else {
                // Tell JS that it needs to do the express install
                ExternalInterface.call(_js_express_install, _js_parent_id);
}

So what we have here is a simple test from the ExpressInstallerUtility for the correct version from a passed in min version. If it passes, great start the app but if not we call a JS function to force an express install and have the user upgrade to the right version.

Interesting enough no to many people have run into this issue before and honestly it only happend a few times in QA but we were able to reporduce it consistantly where FireFox would have the most up to date player yet JS was unable to get the correct version from the browser. Maybe this class is something you should keep in you back pocket for a rainy day.

So what is so special about our home page that we needed to use 9.0.115? Well outside of wanting to use H.264 for our video it would appear that when you upgrade the Flash IDE it automatically forces you to build for 9.0.115. If you use the video component or net stream object and try running your swf in a lower version they don’t work or show up at all. We originally scoped it out to work for 9.0.45 but since Adobe is forcing h.264 down our throats (and that is not a bad thing) they neglected to make it clear that a simple software upgrade would lock us into a player with lower penetration then they were marketing. I wish I could stop posting about this and the ever changing Flash Player upgrades we have endured but it really leaves a bad taste in your mouth when you have to explain to you boss or client you are locked into something with no way to build to a specific player version in the Flash IDE right before launching.

2 Responses to “Express Installer Utility”

  1. Daniel Tome Says:

    Have you tried using swfobject?

  2. FlashBum Says:

    I have been using swfobject for years and we are using something similar at heavy. The problem is not in the JS detection but in the actual version number the browser (Firefox/Safari) returns to JS. At some point, I think in some of the early 9.0.x express installs the browser’s registry may have gotten corrupted or not correctly updated (on a very small margin of people’s computers) causing the above situation. We weren’t able to find any documentation where people desrcript this problem but then again, the only thing that keeps our Home Page video player from working in 9.0.45 is the *new* net stream object. I can reproduce this bug almost consistently on macs.

Leave a Reply