| Register
Saturday, May 17, 2008   

Different SWFs for Different IFs

Created By  Jed Wood, at  6/20/2005 - 4 comments.

Click to view this author's website.

Deploying multiple versions to match the player.


If you're using Flash MX 2004 (Pro or not) and targeting Flash Player 6, you might want to consider publishing two SWFs: one for 6, and one for 7. Doing this will make it possible to provide optimized performance for almost 100% of your audience. I'll give you a quick how-to in just a minute, but firstly here are the sample files so you can follow along at home. You can also see a live demo, by visiting my trusty card sorting application page.


What was the inspiration for this article? Almost a year ago, I came across an extensive comparison of player perfomance statistics over at Oddhammer. Going through the data, two things became clear: Flash MX 2004 export provides an automatic speed boost over files exported with MX; and Flash Player 7 prefers files of its own native version.


Don't change a thing, just publish with MX 2004


When MX '04 first came out, I remember reading somewhere that you'd get a little performance boost just by opening an .FLA and publishing back out to F6 player. According to the Oddhammer tests, it seems to be true.


7 likes 7


Though many of the differences are miniscule, Flash Player 7 will perform better with SWFs that are published specifically for F7 player. When compared to SWFs compiled with the original MX IDE, the difference is huge. All the more reason to go back through and at least publish those old .FLAs from MX 2004.


The Quick How-To


For the rest of this article, I'm going to assume you know how to publish different versions of a SWF. The task we'll be performing is to filter for the user's available Player, and use server-side scripts to serve up the best matching file. There are several different ways to attempt to detect the Flash player, and none of them are perfect. In this case, I'm using a modified form of the "Flash Detection Kit" (FDK) that Macromedia provides. It uses old-school Actionscript to detect the Flash Player version. Instead of just looking for a simple "yes/no" minimum version, I've decided to categorize the site visitors into four groups, based on the Flash Player they have:



  • No player, or less than 6.0.40

  • At least 6.0.40, but less than 6.0.65 (needed for Flash Remoting support on all browsers)

  • At least 6.0.65, but less than 7 (send them to a .SWF that's been optimized for .65)

  • 7 or higher (if they've got 7, of course they get the .SWF for 7)


Your specific needs might differ, but most of the apps I work on use Flash Remoting, so 6.0.40 is my cut-off. While I was in there customizing the FDK code, I chopped out the bits I'm not using. It makes it a little less flexible, but customizing is still pretty quick. Let's look at just the first few lines, where we set up the variables to represent these four different groups:



//the url that the visitor should be sent to if they do not have the required version of Flash.
noflashURL = "noflash.php";
//-------------------
//the urls that the visitor should be sent to if they have the required version of Flash.
//In our, case it's a single script that will interpret the "pv" GET variable and load the appropriate SWF.
goodURL = "flash.php?pv=640";
betterURL = "flash.php?pv=665";
bestURL = "flash.php?pv=7";
//-------------------

As you can see, I've set up four different variables to represent the different URLs. Again, feel free to modify and use the sample files for your own needs. If you're not comfortable using PHP or some other server-side language, just create four different HTML files that embed your different .SWFs.


So if you've spent weeks or months (or years, anyone?) coding a Flash app that reaches a wide audience, take the extra 30 minutes to ensure that all your visitors have the smoothest experience possible.  And if you're already doing something similar and have some thoughts to share, you know where the comments are...


One Last Warning


I hope it goes without saying that you'll want to test the various different .SWFs. I don't have the definitive list of differences, but I'll share one F7 difference (a.k.a. BUG) that tripped me up. There were a few instances in my code where I was appending a string to a variable that was previously not declared. Something in a FOR loop like this:

myString = myString + " hello";

In F6 players, the final output was correct, but in the F7 player, the word "undefined" was actually prepended to the string! The text sent into my database looked like:

undefined hello

Now maybe somebody out there has a documented explanation, but the point is -- make sure you get the archived players from Macromedia's site (or use a fancy player switcher) and test your different versions!

Need Professional Help For Your ActionScript Project?
ActionScript.com Consulting Services provide top quality professional ActionScript consulting to businesses around the globe. If you have a professional project in need to world-class talent, tell us about your project by requesting a quote today.

Reader Comments

  1. philip  Replied:
    ( 6/22/2005 At 1:47 AM)

    I'll have to consider this seriously for my component LivePreviews.
    Flash MX2004 on a Mac is just too slow and on top of that I have a G3 500MHz which makes it just painful to use, but it makes for a great minimum test environment.
    I'll have to try publishing the LivePreviews files out of MX2004. If it makes a significant improvement, I may have to offer my components one for MX and a second for MX2004, even though they only use AS1.

  2. Roger Onslow  Replied:
    ( 8/29/2005 At 2:45 AM)

    > Now maybe somebody out there has a documented explanation
    Yes .. the Flash MX 2004 help files have the explanation. Its all in there.
    Please read the sections within Using ActionScript in Flash : What's New in Flash MX 2004 ActionScript.
    For example, the section on 'ECMA-262 compliance shows you:
    >>>
    When undefined is converted to a string, the result is undefined.
    firstname = "Joan "; lastname = "Flender"; trace(firstname + middlename + lastname); // Joan undefinedFlender
    >>

  3. pankaj kumar  Replied:
    ( 3/2/2007 At 8:28 AM)

    Hi,

    I am facing a problem for making a link on a flash.
    It should be like this that when i click on that link (image) a popup window come up with the message.
    So, for this what should i do?

  4. Pavel --  Replied:
    ( 6/17/2007 At 2:34 PM)

    Older versions of Flash
    http://flash-ascript.blogspot.com/2007/06/first-steps-of-flash-futuresplash.html

Login to post your comments. If you do not have an account with us please Register.
Copyright 2005 by ActionScript, Inc.   |  Privacy Statement  |  Terms Of Use  |  ActionScript Client Extranet