【问题标题】:AS3: Enable features according to Flash Player VersionAS3:根据 Flash Player 版本启用功能
【发布时间】:2010-12-12 17:26:13
【问题描述】:

我想知道是否可以根据 ActionScript 3 中的 Flash Player 版本启用/禁用某些代码。

比方说;我有一个使用flash.media.Microphone 的自定义类customClass。 Microphone 类有一个属性isSupported,它可用于Flash Player 10.1 及更高版本(如文档中所述)。我在我的 customClass 中实现了这个属性......所以:

我需要这样的东西(通过检查内置的Capabilities.version):

if (version >= 10.1) {
    trace(_mic.isSupported); //this will throw an error if the debug version is not 10.1 or later
} else { 
    doSmthElse();
}

有没有办法做到这一点?

【问题讨论】:

    标签: actionscript-3 actionscript version flash detection


    【解决方案1】:

    这是我知道的唯一方法:

    if (version >= 10.1) {
        trace(_mic["isSupported"]); //this will throw an error if the debug version is not 10.1 or later
    } else { 
        doSmthElse();
    }
    

    使用方括号访问语法,验证器不会尝试检查方法或属性是否预先定义(我认为是在加载时)。所以你的代码只会在运行时被评估,如果它真的运行的话。

    【讨论】:

    • 谢谢..这至少有帮助..我还想仔细检查 hasOwnProperty(..)..
    • 我想你可以在 javascript 中进行版本检查,并使用 ExternalInterface API 从 Flex 中的 js 接收消息,并有一个 switch case 函数来启用/禁用功能。
    • @Brian Bishop。我想你可以,但我认为这只是更多的工作而没有真正的好处。问题是没有检测到当前版本,这在 Actionscript 中是微不足道的。问题是验证程序在加载 swf 时验证属性是否已定义(取决于播放器版本)。因此,如果你写了_mic.isSupported,这将在版本 无论你是否实际运行那段代码。
    • 顺便说一下,Microphone.isSupported 是一个静态属性。所以 hasOwnProperty 检查不能用它,但括号访问语法有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 2013-07-28
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多