辅助功能*

目录

Flash Player 检测的最佳实践

实施 Flash Player 快速安装

下面的教程描述如何实施 Flash Player 快速安装机制。

注意: 由于尚未安装 Flash 8 插件的用户无法看到 Flash 8 内容, 会使用另一个 SWF 来代替实际 Flash 内容来处理升级过程。 此 SWF 被命名为 playerProductInstall.swf 并被发布用于 Flash 插件版本 6r65。 按这些步骤操作, 您将了解如何为此 SWF 修改源文件并在升级失败或被取消时提供替代内容。

本教程假定您已将 Flash 8 检测脚本添加到某个网页中 (如实施过程概要中所述) 并已下载 Flash Player Detection Kit:

  1. 从您下载的 ZIP 文件解压缩 Flash Player Detection Kit 文件并找到“Express Installation”目录。
  2. 将下列文件从“Express Installation”复制到硬盘上的某个新文件夹中: playerProductInstall.fla、playerProductInstall.html、playerProductInstall.as 和 playerProductInstallCallback.as。
  3. 在 Flash 创作工具中打开 playerProductInstall.fla。 此文件创建用户没有 Flash Player 8 但有 Flash Player 6r65 或更高版本时看到的 SWF。 更改尺寸和背景颜色以适合您的网页。 通常, 最好使用与您自己的 Flash 内容相同的尺寸, 这样页面呈现不会作为显示 playerProductInstall.swf 的结果受到影响。

    注意: PlayerProductInstall.swf 的尺寸必须至少为 215 x 138 像素, 这是正确显示“快速安装”提示所需的最小空间。 使用“工作区”上的 AutoUpdater 符号实例作为指导。

  4. 在 playerProductInstall.fla 中, 从“工作区”删除说明文本。 请根据自己的喜好更改 AutoUpdater 符号的颜色, 如与背景色混合。
  5. 打开 playerProductInstallCallback.as。该文件确定如果升级失败或被取消时用户所看到的内容。 此 ActionScript 文件中的代码应该是这样的:

    function installStatus(statusValue) {
         if (statusValue == "Download.Complete") {
              // Installation is complete. In most cases the browser window that this SWF 
              // is hosted in will be closed by the installer or manually by the end user.
         }     else if (statusValue == "Download.Cancelled") {
                 // The end user chose "NO" when prompted to install the new player
                 // by default no User Interface is presented in this case. It is left up to
                 // the developer to provide an alternate experience in this case.
         }     else if (statusValue == "Download.Failed") {
                 // The end user failed to download the installer due to a network failure
                 // by default no User Interface is presented in this case. It is left up to
                  // the developer to provide an alternate experience in this case.
         }
     }
    
  6. 使用确定每一事件中会发生的情况的 ActionScript 替换 if/else 语句的每一部分内的注释。 例如, 如果 statusvalue (在该语句的每一部分中进行测试的变量) 等于 Download.Cancelled, 则您可能使用 getURL() 调用来将用户转移到您的站点上的一个不同的页面上。

    看看我的 eReader 应用程序 (www.rhjr.net/eReader*), 其中有一些示例, 介绍它是如何使用的 (当然, 首先您必须卸载您的 Flash Player 版本并安装一个较旧的版本, 然后确保在显示 Flash 插件提示时取消升级)。

    完成后保存您的工作。

  7. 重新发布 playerProductInstall.fla 来创建您的较新版本的 playerProductInstall.swf。保存 playerProductInstall.fla, 关闭全部两个文件, 然后将 playerProductInstall.swf 移动到与您的网页相同的目录中。
  8. 在某个文本编辑器 (如 Macromedia Dreamweaver 8) 中打开 playerProductInstall.html 并在该页面的 BODY 元素内找到 JavaScript。

    此脚本与您早先添加到您自己的网页中的脚本相似, 但它还会检查用户的计算机是否安装了 Flash Player 版本 6r65 或更高版本。 如果已安装, 它就会显示 playerProductInstall.swf, 取代您的 Flash 内容。

    复制整个脚本 (不包括 NOSCRIPT 元素, 它不需要更改)。 稍后, 您会将此脚本粘贴到您自己的页面中。

  9. 在某个文本编辑器中打开您自己的网页 (为了该教程的缘故, 我们将它称为 index.html)。 突出显示 index.html 的 BODY 元素中的脚本并将您从 playerProductInstall.html 复制的脚本粘到其位置。

    如果找到正确的 Flash 插件版本, 此版本会运行, 从而使用您要显示的 Flash 电影的尺寸和名称来替换突出显示的值。

  10. 在 Web 浏览器中打开 index.html 并测试它。 您将需要卸载 Flash Player* 并安装一个较旧的版本*来正确测试它。

如果您是按前述步骤操作的, 则您使用较旧版本的 Flash Player 进入该页面时, index.html 应该立即向您显示“快速安装”升级提示。

下一步工作

若要了解如何利用 Flash Player 快速安装, 请参考 Flash Player Detection Kit。 它还会更加详细地描述在本文中提及的其他检测策略, 包括服务器端和更少脚本方法。 您可以直接看到 Flash 8 检测脚本是如何工作的, 方法是通过在 Flash 8 中创建一个新的 Flash 文档, 打开“发布设置”, 选择“HTML”选项卡, 然后选中“检测 Flash 版本”复选框。 单击“发布”按钮并在您喜爱的编辑器 (如 Dreamweaver 8) 中打开结果 HTML 文件。

有关在 Flash 8 创作工具中使用的脚本的详细说明, 请参阅由 Flash 软件工程师 Michael Williams 写的文章将来证明 Flash Player 检测脚本*, Michael Williams 是 Macromedia 在 Flash 8 检测脚本方面的权威。 特别感谢 Michael, 他在解决有效的 Flash 检测的继续问题方面付出了令人难以置信的努力。 他肩负使命, 任何地方的用户都将受益于他的专业技术。