MACROMEDIA FLASH  back to
DETECTING FLASH 4 WITHOUT SCRIPTING  

detecting flash 4 with flash
detecting flash 4 without scripting uses the exact same logic as detecting flash 2 or 3 without scripting: a hidden movie attempts to redirect the user with a get url action; if the user doesn't have flash, then the get url action never occurs and the browser will do one of two things: 1) version 4 of netscape and ie alert the user that there is flash content and ask the user to go install the plugin (a link is provided in netscape while ie performs autoinstallation) 2) in older browsers, the movie is either ignored or a broken plugin piece may be shown. to prevent the user from being left on a page with no real content, we use a meta refresh to take them to a non-flash page if all else fails. with the advent of flash 4, it becomes much more important to address the audience of users that *do* have flash, but don't have the latest version of the player. our flash 4 non-script detection routine provides alternate redirection to flash 3 and flash 2 pages if the flash 4 plugin is not installed. on those pages we place the appropriate upgrade messages.

here's how it works: we have three get url actions, one for flash 4, one for flash 3, and one for flash 2. the get url for flash 4 goes to the real site. the get urls for flash 3 and 2 go to pages with upgrade information. each get url is called using a version-specific feature of flash. we start with flash 4, the version we most want the user to have. to execute a flash-4 only get url, we create a normal get url on the main movie timeline, but we set the value of the url to an expression. expressions are not interpreted by flash 3 or 2, so the get url would be skipped by those players. next we add a flash 3-only redirection by embedding another get url action in a movie clip. movie clips are ignored by flash 2. finally, we place a normal get url on the main movie timeline which will be executed if flash 2 is installed and the first two redirects have failed. as a final production task, we place a preloader at the beginning of the movie. this ensures that all frames are present before our redirections are attempted (if we don't add a preloader, the actions are sometimes skipped over slower connections).

note that the mime type for flash has to be set correctly on your server for this detection method to work.

how to detect flash 4 (version 1.4)
to detect Flash 4, follow these steps (or skip to the bottom and download the sample files):

  1. create a flash movie with 22 frames.
  2. set the movie size to the smallest it can be (18 pixels square).
  3. create an empty keyframe on frames 5, 6, 10, 11, 15, 20 and 22 of the movie.
  4. on frame 22 of the movie, add a "stop" action. this prevents a problem with ie on mac where the browser endlessly loops the movie.
  5. on frame 10 of the movie, add a get url action with a "url" set to the page that contains your flash 4 content. then set the "abc" button to expression (the two-lines icon). make sure the text in your url is quoted so it is interpreted as a string, not a variable name. here's an example of what your code should look like in the actions listbox:
    Get URL ("flash4page.html")
  6. on frame 11 of the movie, you need to add a little actionscript code that prevents the movie continuing if flash 4 is enabled (otherwise the movie may execute the alternate get urls before the f4 url is loaded). we set a variable in called f4 to "true" and execute a stop action only if the variable can be evaluated to "true" with actionscript. if it can't, we send the movie on its way with a play action. here's the code to add:
    Set Variable: "f4" = "true"
    If (f4 eq "true")
         Stop
    Else
         Play
    End If


    now you may be wondering why we have to put the play action in the else statement because it may seem that a stop action in an if statement would simply be skipped by the flash 3 player. but that's not how it works: the flash 3 player actually executes the last action found inside an actionscript block, so of we didn't add the play action, the movie would simply stop in flash 3.
  7. create a movie clip with four keyframes.
  8. on frame 2 of the movie clip you just created, add a get url action with a "url" set to the page that contains your flash 3 content (you put the get url is inside the movie clip so that only the flash 3 player will execute the command, preventing flash 2 users from wrongfully seeing your flash 3 content). note that you can make the upgrade info different for version 3 and 2, but be aware that this version 3 get url is (very) occasionally skipped in ie when it attempts to autoinstall version 4.
  9. on frame 3 of the movie clip, add a tell target to tell the main movie timeline to stop. this prevents the last get url from being executed before the flash 3 content has loaded. here's what the tell target looks like:
    Begin Tell Target ("/")
         Stop
    End Tell Target
  10. on frame 4 of the movie clip, add a stop action. this prevents the movie clip from looping and repeatedly calling the get url on frame 2.
  11. place your movie clip on the movie stage at the 15th frame of your main movie timeline.
  12. on frame 20 of the movie, add a get url action with a "url" set to the page that contains your flash 2 content.
  13. next we add the preloader that ensures our get urls will be executed properly. on frame 5 of your main movie timeline, add an "if frame is loaded" action. in the "number" text field of the "frame" option for your action, enter the number 22 (we preload our entire movie).
  14. with the line that reads "if frame is loaded (22)" highlighted, add a "go to" action. check the "go to and play" checkbox of the "control" option. then, in the "number" text field of the "go to" option for your action, enter the number 7.
  15. to finish the preloader, add a "go to" action on frame 6 of the movie. check the "go to and play" checkbox of the "control" option. then, in the "number" text field of the "go to" option for your action, enter the number 4.
  16. you're done the movie, now all you have to do is embed it onto an html page with a meta refresh set to take the user to a non-flash page after 20 seconds (perhaps longer if you are hosting your site on a really slow server).
    meta tag notes:
    • here's a sample meta tag:
      <META HTTP-EQUIV="Refresh" CONTENT="20;URL=nonflash.html">
    • you can adjust the amount of time the meta tag waits before taking the user to the non-flash page by changing the number "20" in the code above. remember that on older machines, browsers take 5-10 seconds to load the flash plug-in.
    • in netscape, make sure you don't include the "swLiveConnect=true" parameter in your movie embed tag, otherwise the browser will pause for 5-20 seconds while loading java. if your site uses fs command, you should enable liveconnect on subsequent pages.
    • there is a strange behaviour on some linux versions of netscape where the meta refresh will be executed even after flash has redirected to the appropriate flash page. to avoid that, you could use javascript's window.location to redirect instead of meta, but then some users may have javascript turned off so they won't get redirected. linux users tend to be techies anyway, so it might be best to let them figure out what's happening rather than risk losing javascript-disabled users. as with all detection, it's just a call you have to make based on your knowledge of your audience. whatever the decision though, always have a link to your flash and non-flash content somewhere on your pages.
    • remember to make sure that the colour of your flash movie and your html document are the same.
  17. also on the html page, make the process feel natural for the user by adding a "loading..." message centred in the middle of the screen (using a table). also, you'll need to explain the upgrade process for Flash 2 & 3 users in the alternate flash movies. finally, on your non-flash page, describe how to get flash.
try it out using the example below, then download the .zip of the example for your own use (open "detect4-noscript.html" once the files are unzipped).

example: detecting flash 4 using a hidden movie.
>>try it out
>>download the .zip of the files used in the example

revision history
  1. july 14, 1999: posted.
  2. july 14, 1999: added a few frames to the beginning of the movie because it was getting skipped in some cases under netscape. thanks judith for reporting the error.
  3. july 22, 1999: added a preloader to the movie so all the frames are guaranteed to be present before the movie starts to play. the get url actions were still getting skipped on slower connections.
  4. july 22, 1999: later that day. added version-specific stop actions after the flash 4 and 3 get urls because on slow connections, the movie continued playing and executed all three get urls, meaning that flash 4 users on modems tended to get either the flash 3 or flash 2 upgrade page.
  5. july 27, 1999: i noticed that the flash 3 player was now stalling before the flash 3 get url was being executed. on investigation, i found that the way flash 3 ignores actionscript is to actually execute the last action within an if statement. this was causing the stop action i added on july 22nd to prevent the flash 3 player from continuing. i've adjusted the actionscript so it now issues a play command as the last statement if the f4 variable evaluates to anything other than "true".
  6. november 30, 1999: added a stop action to the last frame of the flash 3 redirect movie clip. this prevents the clip from looping and repeatedly calling the flash 3 url in that version of the player. thanks to tony vidmer for pointing out the bug. also updated the codebase of the flash object tag, and added a warning about mime type being required.