|DETECTING FLASH 4, 3, AND 2 WITHOUT SCRIPTING
detecting flash 4.0r11 and earlier within flash
occasionally it's useful to detect flash internally after a movie has loaded. starting with version 4.0r11 and later, we can do so with the built-in $version variable. before that, however, we have to be a little more inventive with our detection methods. for the sake of demonstrating how to detect flash with those alternative methods, this article will explain how a getURL can send users to a flash 2 page, a flash 3 page, or a flash 4 page, depending on which version of the player they have. you could, of course, apply the same techniques to display alternate content directly in flash.
our demonstration shows how a small movie can redirect the user with a get url action that matches the version of the player hosting the movie.
here's how it works: we have three get url actions, one for flash 4, one for flash 3, and one for flash 2. each get url is called using a version-specific feature of flash. we start with flash 4. 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 will be skipped by those players. next we create a flash 3-only get url by placing a get url action in a movie clip. movie clips are ignored by flash 2, so our get url will never execute in 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: if the user doesn't have flash at all we get some undesired behaviour. the browser will do one of two things: 1) if it's version 4 of netscape or any version of ie, the user is alerted that there is flash content and asked 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 avoid this behaviour, you should do real detection with a system like the moock fpi.
remember that this example shows the use of get urls, but we could easily use goto actions instead. goto actions would actually be preferable because we'd be keeping the user in our current movie and just sending them to the appropriate section for their player version.
because scripts in flash 5 movies are not executed by the flash 4 player, the example described below will work only with movies exported in flash 4 format. *however*, exporting the movie in the example as version 4 from the flash *5* authoring tool will not work, and may cause crashes on browsers with older versions of the plugin. it appears that the flash 5 export of the v4 movie is not identical to the flash 4 export of the v4 movie. the only solution i know of is to use flash 4 to export the v4 movie.
building an internal detector (version 1.4)
you've read the approach. here's how to build it. (sample files are also posted at the bottom of the page):
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).
- create a flash movie with 22 frames.
- set the movie size to any size. i use the minimum, 18 pixels square.
- create an empty keyframe on frames 5, 6, 10, 11, 15, 20 and 22 of the movie.
- 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.
- 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")
- 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 called f4 to "true" and execute a stop action only if the variable can be evaluated to "true" with actionscript. if the player can't execute the code we know it's less than version 4 so 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")
now you may be wondering why we have to put the play action in the else statement. you might think 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.
- create a movie clip with four keyframes.
- 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).
- 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 ("/")
End Tell Target
- 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.
- place your movie clip on the movie stage at the 15th frame of your main movie timeline.
- on frame 20 of the movie, add a get url action with a "url" set to the page that contains your flash 2 content.
- 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).
- 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.
- 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.
- you're done the movie, now all you have to do is embed it onto an html page to see it work.
example: detecting flash 4 using a hidden movie.
>>try it out
>>download the .zip of the files used in the example
- revision history
- july 14, 1999: posted.
- 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.
- 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.
- 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.
- 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".
- 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.
- june 8, 2000: revised the focus of the page. due to the creation of the moock fpi, the detection techniques shown here are no longer appropriate as a stand-alone detection solution. use this information only as a component of a larger detection system. that is, detect flash first, and then use this system to display version-specific content in your movie.
- april 17, 2001: added warning about problematic v4 export of the detection movie from flash 5. thanks to brian strauss for pointing it out.