Detecting the Flash Player


What good is an awesome Flash experience if no one can see your Flash movies? Because most Flash content is viewed with a Web browser, it's extremely important to make sure that your HTML pages check for the existence of the Flash Player plug-in before you start pushing Flash content to the browser. There are a variety of ways to check for the Flash Player, and this section provides an overview of the available methods.

New Feature 

As we mentioned in the previous chapter, Flash 8 includes an updated Flash Player detection feature within the Publish Settings. You learn how to create a set of detection pages with this new feature later in this chapter.

Plug-In versus ActiveX: Forcing Content without a Check

The Flash Player is available for Web browsers in two forms: the Flash Player plug-in (as a Netscape-compatible, or Mozilla-compatible, plug-in) and the Flash Player ActiveX control (for use only with Microsoft Internet Explorer on Windows 98/ME/2000/XP).

If you directly insert a Flash movie into a Web page with the <embed> tag (for Netscape browsers), one of two scenarios will happen:

  • The browser has the Flash Player plug-in and will load the Flash movie.

  • The browser does not have the Flash Player plug-in and displays a broken plug-in icon.

If the second scenario occurs and the pluginspage attribute of the <embed> tag is defined, the user can click the broken plug-in icon and go to the Macromedia site to download the Flash Player plug-in. If the pluginspage attribute is not specified, clicking the broken plug-in icon will take you to a generic Netscape plug-in page.

If you insert a Flash movie into an HTML document with the <object> tag (for Internet Explorer on Windows only), one of two scenarios will happen:

  • The browser has the Flash Player ActiveX control and will load the Flash movie.

  • The browser does not have the Flash Player ActiveX control and will autodownload and install the ActiveX control file from the Macromedia site.

Note 

Newer versions of Windows XP (that is, with Service Pack 2 or SP2 installed) will likely get an additional warning represented as a strip across the top of the Web page attempting to initiate the installation of a new ActiveX control. The user must also click this strip and accept the download of the ActiveX control.

The ActiveX control will autodownload and install only if the classid and codebase attributes of the Flash movie's <object> tag are correctly specified. Depending on the user's security settings, the user needs to grant permission to a Security Warning dialog box to commence the download and install process.

Although using the <object> and <embed> tags by themselves is by far the simplest method for integrating Flash content into a Web page, it's not the most user-friendly method of ensuring that the majority of your Web visitors can view the Flash content. Flash 8 uses a new JavaScript detection mechanism, updating the Flash sniffer approach used in Flash MX 2004.

Note 

Since Flash Player 4 was released, many seasoned Flash developers have used small Flash movies known as sniffers to detect the presence of the Flash Player in a user's Web browser. Sniffers are virtually hidden from the visitor to a Web site, and they direct an entry HTML page to a new location (using a getURL() action) where the real Flash content (or site) exists. If the Player is not installed, the sniffer movie won't be able to play and direct the HTML page to a new location. If this happens, a special <meta> tag in the <head> of the HTML document directs the browser location to a screen that informs the visitor to down load the plug-in or ActiveX control.

Detecting the Flash Player with Flash 8

In Flash 8, Macromedia has made the process of using a sniffer methodology incredibly simple. In the following steps, you learn how to use the new Detect Flash Version feature to properly direct a user to Flash Player 6 r65 content.

Note 

You can check for Flash Player 4 or higher with the Detect Flash Version feature. For demonstration purposes, we chose Flash Player 6 r65 because Flash MX 2004 introduced a new optimization feature for .swf files generated for this version (or higher) of Flash Player 6.

Caution 

If you use the Detect Flash Version in Flash MX 2004, be sure to review this section. The feature no longer uses three HTML pages for the detection process. Everything from the detection to the content display to the alternate content display occurs on one HTML page.

  1. Create a new Flash document by choosing File ð New. In the New Document dialog box, choose Flash Document and click OK. Alternatively, open an existing .fla file that you have created and skip to Step 4.

  2. Save the new Flash document as detection_test.fla.

  3. Add some placeholder text to the stage using the Text tool. As this example is checking for Flash Player 6 r65, you can type This is Flash Player 6 r65 content.

  4. Choose File ð Publish Settings. By default, both the Flash and HTML formats are selected in the Formats tab of the Publish Settings dialog box. The filenames for these formats should reflect the current .fla filename, such as detection_test.swf and detection_test.html, respectively.

  5. To keep the new version settings in a separate profile, click the Create New Profile (+) button at the top of the Publish Settings dialog box. Name the profile FP6 r65 Detection, as shown in Figure 22-3. Click OK to close the dialog box, but leave the Publish Settings dialog box open.

  6. Click the Flash tab. In the Version menu, choose Flash Player 6. In the ActionScript version menu, choose ActionScript 1.0. Select the Optimize for Flash Player 6 r65 check box. Refer to Figure 22-4 for a review of these settings.

  7. Click the HTML tab of the Publish Settings dialog box. Select the Detect Flash Version check box. The two editable text fields to the right of the Version label should now be enabled. The major version of the Flash Player is fixed to the Player version you chose in the Flash tab. The first of the two editable fields represents a Minor Revision value; to date, Macromedia hasn't released any minor revisions of the Flash Player, but this feature is enabled just in case Macromedia does release any minor revision during the life cycle of the Flash 8 authoring tool. The second field represents the Incremental Revision value. Since Flash Player 4, Macromedia has released several incremental revisions of the Flash Player for each player cycle.

    Web Resource 

    To get a sense of how many incremental revisions of Flash Player 7 were released, see the "Flash Player Release Notes" category at www.flashsupport.com/links.

    Caution 

    In Flash MX 2004, Macromedia referred to these two editable values as Major Revision and Minor Revision. With a little revisionist history in Flash 8, Macromedia now refers to Major Revision as Minor Revision and Minor Revision as Incremental Revision.

    Type 65 in the second field, as shown in Figure 22-5. If you wanted to check for a different incremental version of Flash Player 6, you could enter that value instead. Click OK to close the dialog box, and go back to the HTML tab of the Publish Settings dialog box.

  8. In the Publish Settings dialog box, click the Publish button. You may see an alert box, as shown in Figure 22-6, letting you know that the Flash movie file (.swf) you are about to publish is only compatible with Flash Player 6 r65 or higher. Click OK in this alert box. Flash 8 generates all of the necessary JavaScript within the published HTML document to properly detect the Flash Player version. Click OK to close the Publish Settings dialog box.

  9. On your desktop, navigate to the folder where you saved your original .fla file. If you created the sample document in Step 1, you want to find the location of detection_test.fla. In this location, you will see the HTML file used for the detection process, the Flash content, and the alternate content.

  10. In your own Web browser, load the detection_test.html page. If your browser has Flash Player 6 r65 or higher, the browser should display your detection_test.swf movie. This process works because the detection_test.html page uses JavaScript (or VBScript on Internet Explorer for Windows) to check the installed Flash Player version, if one exists. If you open the HTML document in a text editor such as Macromedia Dreamweaver, you'll see that lines 10–15 declare the version numbers you entered in the HTML tab of the Publish Settings. The JavaScript code compares these values to the version of the Flash Player that loaded the movie. If the Flash Player matches (or exceeds) the version requirements, the Flash content tags (<object> and <embed>) are written to the HTML page with JavaScript. Otherwise, the alternate content specified on line 147 in the JavaScript code is loaded into the browser window.

    Note 

    Macromedia provides generic alternate content that you should replace with your own preferred HTML tags indicating what you want to the user to do if the version of the Flash Player required is not installed.

  11. To accurately test your pages over an Internet connection, upload all of the files (except the .fla file) to your Web server and load the detection_test.html document from the Web server URL to redo the test.

image from book
Figure 22-3: The Create New Profile dialog box, showing the new profile name

image from book
Figure 22-4: The Flash Player 6 r65 settings in the Flash tab

image from book
Figure 22-5: The Publish Settings dialog box

image from book
Figure 22-6: The Optimize for Flash Player 6 r65 alert box

On the CD-ROM 

You can find all of these files created for this detection example in the ch22/flash8_detection folder of this book's CD-ROM. The JavaScript in the detection_test_f8b.html version of the document contains additional alternate content that is specified in an alternate.js file, also included on the CD-ROM. If you'd like to find the latest "Get Flash Player" graphics to use in your Web pages, go to www.macromedia.com/macromedia/style_guide/buttons.

If you want to test the detection mechanism with an older version of the Flash Player, we recommend that you use an older Flash Player installer with Netscape or a Mozilla-compatible browser. The process of uninstalling an ActiveX control used by Internet Explorer is much more difficult to do.

Web Resource 

You can find just about every past version of the Flash Player at www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14266 for testing purposes. As mentioned previously, we recommend that you install the older versions with a Netscape or Mozilla-compatible browser. If you are using Mac OS X, the first Flash Player released for Mac OS X was version 5.

You can set up your Netscape or Mozilla-compatible browser's plug-ins folder to accommodate multiple versions of the Flash Player plug-in. When you installed Flash 8, the first release of Flash Player 8 should have automatically been installed to your Netscape (or Mozilla) browser's Plugins (or plugins) folder. The plug-in file, named NPSWF32.dll, can be moved outside of the Plugins folder, into a new parent folder that you create. For the following example, we'll use Mozilla FireFox as our test browser.

Web Resource 

Mozilla FireFox is a free Web browser that you can download at www.mozilla.org/products/firefox/. FireFox has quickly become the preferred cross-platform browser of many Web developers.

We prefer to create a _Flash Players folder in the C:\ProgramFiles\MozillaFireFox folder, and put each Flash Player version plug-in file into its own folder, as shown in Figure 22-7.

image from book
Figure 22-7: A sample Flash Players folder structure for use with Mozilla FireFox on Windows

Caution 

Regardless of the Flash Player version you install, all Flash Player plug-in files for Netscape or Mozilla-compatible browsers have the same name on Windows: NPSWF32.dll. For this reason, you must isolate multiple installations of the Flash Player into their own folder.

You can do the same procedure on Mac OS X, where all browsers share the same plug-in folders. That's right! Mozilla, FireFox, Internet Explorer, and Apple Safari all refer to the same plug-ins folder. On your boot disk, such as Macintosh HD, browse to the Library\Internet Plug-Ins\ folder. In this location, you will find the Shockwave Flash NP-PPC plug-in file. As Figure 22-8 shows, you can create a Library\Internet Plug-Ins (DISABLED) folder to store other versions of this plug-in file.

image from book
Figure 22-8: A sample Flash Players folder structure for use with Mozilla FireFox or Apple Safari on Mac OS X

Caution 

On Mac OS X, you may need to re-create the same plug-in structure with the Users\[Your User Name]\Library\Internet Plug-Ins\ folder. Or, you may just want to remove any Flash Player plug-in files within this folder. Mac OS X should then default to the main Library\Internet Plug-Ins\ folder.

This process takes some time, as you have to download and run each installer from the URL we mentioned in the earlier Web Resource note, and move the NPSWF32.dll file from the Plugins folder to its own folder in the Flash Players folder. When you're done, however, you'll have an efficient system for checking your content against older versions of the Flash Player. Simply move the current NPSWF32.dll file into its appropriate _Flash Players folder, and move the desired test version from its Flash Players folder into the Plugins folder.

Building Your Own Flash Sniffer Movie

While the Macromedia Flash 8 detection features work wonderfully, you may want to know how to build your own custom Flash detection sniffer. In this section, you learn how to build a Flash movie that uses client-side ActionScript to direct the browser window to the appropriate content. This sniffer directs each version of the Flash Player to its own unique HTML page. Meaning, Flash Player 3 (or earlier) is directed to a flash3.html page, Flash Player 4 is directed to a flash4.html page, Flash Player 5 jumps to a flash5.html page, and so on.

Making the Sniffer Movie

The sniffer movie is a small Flash movie that has the same background color as the HTML document. You do not need any artwork or symbols in this movie.

  1. Open Flash 8, and in a new Flash document file (.fla), rename Layer 1 to actions.

  2. Add a keyframe on frame 2 of the actions layer. With this keyframe selected, open the Actions panel (F9 or Option+F9 on Mac).

  3. In the Actions panel, add some ActionScript that checks for Flash Player 3 (or earlier). If Flash Player 3 is detected, then the movie will stop here and launch a URL for Flash 3 movies. If a later version of the player is detected, a separate keyframe labeled checkPlayer is called. You can direct each version of the Player to a unique URL. The basic principle of this ActionScript is to use Flash version-specific actions to determine which Player is displaying the movie. Refer to Listing 22-1.

    Listing 22-1: The Detection Script on Frame 2 of the actions Layer

    image from book
     // create a Flash variable, whose value is equal to the // $version environment variable in Flash Player 4, 5, // or 6. This action line will not be read by Flash // Player 3(or earlier). player = eval("$version"); // The $version value will be in the format: // // abc 1,2,3,4 // // where abc is the operating system (e.g. WIN, MAC) // and 1 and 2 are the major version designations // (e.g. 4.0, 5.0, etc.) and 3 and 4 are the minor and // sub-minor version designations (e.g. r20, r27, etc.) // // By default, Flash MX 2004 ships with a Player version equal // to WIN 7,0,0,0 or MAC 7,0,0,0. However, the Flash // Player is available on other platforms like UNIX and // POCKETPC as well. // // We just need the major version designation at // placeholder 1. Using a while loop and substring(), we // can extract this number, searching for the space (" ") // between the platform text and the version numbers. The // major version starts just after the space (" "). The // Flash Player 3 will disregard this section of code. playerLength = length(player); i=1; while (i<=playerLength) {    currentChar = substring(player, i, 1);    if (currentChar eq " ") {       platform = substring(player, 1, i-1);       majorVersion = substring(player, i+1, 1);       break;    }    i = i+1; } // This code will check the value of majorVersion. // Flash Player 3 will not be able to execute the // call() action, but Flash Player 4 or higher will. if (majorVersion == " ") {    // Flash Player 3 will execute this code    // automatically, because it will not interpret    // the if action.    getURL("flash3.html"); } else {    call("checkPlayer"); } // We will prevent the movie from accidentally looping. stop (); 
    image from book

  4. Now you need to create a keyframe with actions that will be executed by Flash Player 4, 5, or 6. Add a keyframe on frame 5, and in the Property inspector assign a label of checkPlayer in the <Frame Label> field. Press the F5 key on frame 20 to add more empty frames to the layer so that you can read the frame label.

  5. Select frame 5, and open the Actions panel (F9, or Option+F9). Type the following code into the Script pane. The code in Listing 22-2 checks to see if the Flash Player is version 4, 5, or 6 (or higher).

    Listing 22-2: The Script on the checkPlayer Frame of the actions Layer

    image from book
     // majorVersion will be equal to either 4, 5, 6, 7, or 8 in // Flash Player 4, 5, 6, 7, or 8 (or higher) respectively. if (Number(majorVersion) == 4) {    // Flash Player 4 will execute this code.    getURL("flash4.html"); } else if (Number(majorVersion) == 5) {    // Flash Player 5 will execute this code.    getURL("flash5.html"); } else if (Number(majorVersion) == 6) {    // Flash Player 6 will execute this code.    getURL("flash6.html"); } else if (Number(majorVersion) == 7) {    // Flash Player 7 or higher will execute this code.    getURL("flash7.html"); } else if (Number(majorVersion) >= 8) {    // Flash Player 8 or higher will execute this code.    getURL("flash8.html"); } 
    image from book

  6. Change the size of the movie frame to 18 px × 18 px, in the Document Properties dialog box (Modify ð Document). Change the background color of the movie to match the background color of the HTML document. Click OK.

    New Feature 

    In Flash 8, you can now specify movie dimensions as small as 1 px × 1 px. While 18 px × 18 px is small enough to remain unnoticeable on a Web page, you can opt to make your Flash movie even smaller.

  7. Save the Flash movie as sniffer.fla.

  8. Open the Publish Settings dialog box (File ð Publish Settings). Make sure the Flash and HTML options are selected in the Formats tab. Rename the HTML file sniffer_start.html.

  9. In the Flash tab, select Flash Player 4 in the Version drop-down menu.

    Note 

    You are using the Flash Player 4 format because Flash Player 3 ignores all Flash 4 or higher actions, and Flash Player 4 or higher recognizes the formatting of the variable and ActionScript structures. Flash Player 5 .swf files restructure variables and ActionScript (even Flash 4-compatible code) in a manner that doesn't work consistently in Flash Player 4.

  10. In the HTML tab, select the Flash Only template. Click the Publish button located at the bottom of the Publish Settings dialog box.

  11. When the files have been published, click OK to close the Publish Settings dialog box. Save your document again.

You now have sniffer_start.html and sniffer.swf files in the same folder as your sniffer.fla file. In the next section, you add some additional HTML tags to the sniffer. html document.

Integrating the Sniffer Movie into an HTML Document

After you have made the sniffer.swf and the sniffer.html files, you can modify the HTML document to guide the browser to a unique URL where plug-in information and a down load screen are shown. Remember that the indicates a continuation of the same line of code. Do not insert this character into your HTML document.

  1. Open the sniffer_start.html file in your preferred HTML document editor. Macromedia Dreamweaver, Notepad (Windows), TextEdit (Mac), or BBEdit (Mac) will do just fine.

  2. Somewhere between the <head> </head> tags, insert the following HTML <meta> tag as one line of code:

     <meta http-equiv=" Refresh" content="3; url=download.html" /> 

    This <meta> tag has two attributes, http-equiv and content. The http-equiv attribute instructs the hosting Web server to add the value of http-equiv as a discrete name in the MIME header of the HTML document. The value of the content attribute becomes the value of the MIME entry. Here, the Web browser will interpret the META tag as

     Refresh: 3; URL=download.html 

    in the MIME header. This name/value pair tells the browser to reload the browser window in three seconds with the file download.html. After testing, you may decide to increase the time the browser waits before reloading a new URL. On slower connections (or during peak Internet hours), you may find that three seconds is not long enough for the initial HTML and Flash movie to load into the browser.

    Caution 

    Some older browsers may require an absolute URL in the content attribute. This means that you may need to insert a full path to your HTML document, such as http://www.yourserver.com/download.html, as the URL in the content attribute.

  3. You may want to create some text on this HTML document that indicates its purpose. If the user does not have the plug-in installed, he or she will be staring at a blank white page until the refresh is activated. For the purposes of this example, create an HTML table that centers the text "Checking for Flash Player " on the page.

  4. Save the HTML file as sniffer.html. If you want this to be the default page for your Web site, you may need to rename this file to index.html, idex.htm, index.cfm, or to whatever filename your Web server is configured to use as a default page. At this point, you need to create a download.html file. You also need to create flash3.html, flash4.html, flash5.html, flash6.html, and flash7.html files for the getURL() actions in the sniffer.swf movie.

On the CD-ROM 

We have included sample sniffer.html, download.html, flash3.html, flash4.html, flash5.html, flash6.html, flash7.html, and flash8.html files in the ch22/custom_sniffer folder on this book's CD-ROM. The Flash movie placeholder documents (for example, flash3.html, flash4.html, and so on) do not contain any Flash content. Note that the download.html sample file uses the JavaScript and VBScript player detection discussed in the next section.

When you have your HTML documents ready, you can load the sniffer.html document into a browser. If the Flash Player is not installed, then the meta tag should transport the browser location to the download.html URL. If the Flash Player is installed, then the Flash ActionScript directs the browser to the appropriate page.

Detecting the Flash Player with JavaScript and VBScript

The use of scripts written into an HTML document is also popular for Flash Player detection. If you're getting familiar with ActionScript syntax, you'll find that JavaScript detection code isn't all that complex. JavaScript is a universal scripting language that most 3.0 or higher Web browsers can employ to some capacity. Microsoft's implementation of JavaScript, called JScript, isn't exactly the same as JavaScript found in other browsers. For this reason, you can translate some JavaScript functionality into Microsoft's proprietary Web-scripting language, VBScript.

On the CD-ROM 

You'll find the HTML, Flash documents, movies, and GIF files for this section in the ch22/javascript_detection folder of this book's CD-ROM.

In this section, we look at how to create an HTML document that checks for the presence of the Flash Player plug-in with JavaScript, and the Flash ActiveX control with VBScript. We use two images of a traffic light — one Flash movie with a green light animating on and off, and one GIF image with a red light on — to display the results of our plug-in and ActiveX detection. Many Web sites employ a similar mechanism: Before an HTML page with Flash content can be accessed, visitors are presented with a splash screen telling them whether they have the Flash Player installed. If they don't have it, they can click a link to get the plug-in or ActiveX control. As a backup, many splash pages also include a link to bypass the detection in case the detection fails. This link would take the visitor straight to the HTML document that contains the Flash content.

Caution 

The Flash Player can be detected with most JavaScript-enabled Web browsers by using the JavaScript array navigator.mimeTypes. The value for this array is always empty for Internet Explorer browsers, including IE 4.5 on Macintosh. IE 5.0 (or higher) for Macintosh provides support for this array. While you can use VBScript to detect for IE on Windows, there is no script plug-in detection available for IE 4.5 on Macintosh. You can however, use the Flash sniffer method, discussed in the previous sections, to detect Flash on IE 4.5 on Macintosh.

Detecting the Plug-In with JavaScript

By using JavaScript code, you can set up a testing mechanism that delivers one of two graphics to the visitor's Web browser.

Copy the script_detection.html document located in the ch22/javascript_detection folder of this book's CD-ROM and open it in your preferred text editor (TextEdit, Notepad, BBEdit, and so on), or, even better, in Macromedia Dreamweaver. Look at lines 22 through 27 in the following listing.

Note 

The indicates a continuation of the same line of code. It should not be written in the actual JavaScript code in the HTML document.

 22. var plugin = 0; 23. var activeX = 0; 24. var plugin = (navigator.mimeTypes &&     navigator.mimeTypes["application/x-shockwave-flash"])image from book     ? navigator.mimeTypes["application/x-shockwave-image from book     flash"].enabledPlugin : 0 25. if (plugin) { 26.   plugin = parseInt(plugin.description.substringimage from book       (plugin.description.indexOf(".")-1)) >= 8 27. } 

Line 22 initializes a variable plugin to save a value that indicates the presence of the Flash Player 8 plug-in on Netscape (or Mozilla, FireFox, IE 5.0 Mac, or Apple Safari). Line 23 initializes a variable called activeX to save a value that indicates the presence of the Flash Player 8 ActiveX control. At this point, you assign a value of 0 to these variables, meaning that the plug in and ActiveX Control are not installed. This is used for worst-case scenarios in which the user may be using a version of JavaScript that doesn't interpret the detection code correctly.

Line 24 is borrowed from the Detect Flash 6 HTML template output from Flash MX (not Flash MX 2004 or Flash 8). It uses the mimeTypes array of the navigator JavaScript object to determine whether the Flash Player (in any version) is installed. If the Flash Player plug-in is installed, the variable plugin is now equal to the value [object Plugin]. If this is true, lines 25 and 26 will execute. Using the description property of the Plugin object, you can determine whether the Flash Player is the correct version. In this example, you check whether it's greater than or equal to 8. Notice that you can use a comparison as the value of the plugin variable. If Flash Player 8 (or higher) is installed, plugin will equal true (or 1); if a lower version is installed, plugin will equal false (or 0).

Creating a Test Object in VBScript

At this point, if the visitor is using Netscape (or a Mozilla-based browser, on any operating system) or Internet Explorer on the Macintosh, the variable plugin will have a value of either 0 or 1. However, you still need to check for the ActiveX control if the visitor is using Internet Explorer for Windows. Line 13 already initialized a variable called activeX. Lines 28 through 33 check to see if VBScript can create a Flash object in the document:

Note 

The image from book indicates a continuation of the same line of code. It should not be written in the actual JavaScript code in the HTML document.

 28. else if (navigator.userAgent &&image from book       navigator.userAgent.indexOf("MSIE")>=0 &&image from book       navigator.userAgent.indexOf("Windows")>=0){ 29.   document.write(‘<SCRIPT LANGUAGE=VBScript\> \n'); 30.   document.write(‘on error resume next \n'); 31.   document.write(‘activeX = (IsObject(CreateObjectimage from book       ("ShockwaveFlash.ShockwaveFlash.8")))\n'); 32.   document.write(‘<' + ‘/SCRIPT>'); 33. } 

Line 28 determines whether the visitor is using Internet Explorer on Windows. If that's the browser the visitor is using, lines 29 to 33 will execute. These lines of code create the VBScript that is necessary to check for the existence of the Flash Player 8 ActiveX control. Using the IsObject() and CreateObject() methods, VBScript can determine whether the ActiveX Control is installed. If it is installed, the variable activeX equals true (or 1). Note that this variable is available to both JavaScript and VBScript.

Inserting the Graphics

After the variables plugin and activeX have been set appropriately, you can use these variables to either display a Flash movie file (.swf) or a GIF image graphic. In the body of the HTML document, you can reuse the plugin and activeX variables to insert either the Flash or GIF graphics. Lines 43 through 48 of the HTML document will write the tags to display the Flash movie or the GIF image for Netscape/Mozilla browsers (on any platform) or IE on the Mac.

Note 

The image from book indicates a continuation of the same line of code. It should not be written in the actual JavaScript code in the HTML document.

 43. if (plugin) { 44.   document.write('<embed src="/books/4/403/1/html/2/ trafficlightgreen.swf"image from book       width="105" height="185" swliveconnect=" false" image from book       quality=" high"></embed><br/>Flash Player 8<br/>plug-inimage from book       detected.'); 45. } else if (!(navigator.appName &&image from book       navigator.appName.indexOf("Netscape")>=0 &&image from book       navigator.appVersion.indexOf("2.")>=0)){ 46.     document.write(‘<a href=" http://www.macromedia.comimage from book           /go/getflashplayer/">'); 47.     document.write(‘<img src="/books/4/403/1/html/2/ trafficLightRed.gif"image from book           width="105" height="185" border="0" /></a><br/>image from book           Flash Player 8<br/>plug-in not installed.'); 48. } 

If the plugin variable is not equal to false (line 31), line 43 executes. Line 43 uses the <embed> tag to insert a Flash movie file (.swf), depicting a green light that animates to a full green color, and the HTML text "Flash Player 8 Plug-in detected." If the plugin variable is equal to false and the browser is Netscape 2.0 (or Mozilla-compatible) or higher (line 43), then lines 44 and 45 create <a href> and <img> tags, depicting a static GIF image of a red traffic light that links to the Macromedia download area. Then, JavaScript creates the HTML text "Flash Player 8 plug-in not installed."

Note 

The following discussion refers to lines not shown in the code listings for this section. Please refer to these lines (and line numbers) within the script_detection.html document in your preferred text editor.

Lines 55 through 64 perform the same functionality for Internet Explorer for Windows. If the activeX variable is true, then an <object> tag is written and a green traffic light animates on. If it's not installed, then a static GIF image of a red traffic light is displayed. Finally, you should do two more things:

  • Tell IE 4.5 (or earlier) Mac users that you can't detect the Flash Player 8 plug-in.

  • Tell other users that they can either proceed to the main Flash site, or click the appropriate traffic light to download the plug-in or ActiveX control.

Lines 72 to 75 tell IE 4.5 (or earlier) Mac users that you can't detect their plug-in settings. You can either leave it to them to decide whether they should download the plug-in, or you can direct them to a sniffer movie (discussed in the previous section) to determine whether the plug-in is installed.

Lines 76 to 78 check whether either the plug-in or the ActiveX control is installed. If it is, you tell the visitor to proceed to the main Flash site. Note that you'll want to insert more JavaScript code here that includes a link to your Flash content.

Lines 79 to 87 check whether the plug-in and the ActiveX control are both absent. If neither is installed, you tell them which traffic light (lines 80 to 87) to click.

Although you'll most likely want to spruce up the look and feel of this page to suit your particular site, you can use this scripting layout to inform your visitors about their plug-in or ActiveX control installations.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net