Actionscript 3 ActionScript/AIR-在运行时确定设备配置文件?

Actionscript 3 ActionScript/AIR-在运行时确定设备配置文件?,actionscript-3,air,matrix,bitmap,cache-control,Actionscript 3,Air,Matrix,Bitmap,Cache Control,我正在为桌面和移动设备开发一个应用程序,并希望为每个构建使用相同的代码库 我想在我的一些显示对象上使用cacheAsBitmapMatrix,但是cacheAsBitmapMatrix如果包含在设备配置文件不是mobileDevice或extendedMobileDevice的AIR应用程序中,则会抛出错误 类似于以下内容的内容将是理想的: if (cacheAsBitmapMatrix.isSupported) myDisplayObject.cacheAsBitmapMatrix =

我正在为桌面和移动设备开发一个应用程序,并希望为每个构建使用相同的代码库

我想在我的一些显示对象上使用
cacheAsBitmapMatrix
,但是
cacheAsBitmapMatrix
如果包含在设备配置文件不是mobileDevice或extendedMobileDevice的AIR应用程序中,则会抛出错误

类似于以下内容的内容将是理想的:

if (cacheAsBitmapMatrix.isSupported)
   myDisplayObject.cacheAsBitmapMatrix = new Matrix();
使用try/catch更新:

try                {myDisplayObject.cacheAsBitmapMatrix = new Matrix();}
catch(error:Error) {}
finally            {myDisplayObject.cacheAsBitmap = true;}

更新:

除电视配置文件外,这也应适用于区分移动和桌面:

//Resoslve Profile
if  (Capabilities.os.indexOf("Windows") > -1 || Capabilities.os.indexOf("Mac") > -1 || Capabilities.os.indexOf("Linux") > -1)
    trace("Desktop Profile");
    else
    trace("Mobile Profile");

更新2:

在运行时确定概要文件的最简单的方法可能是调用:

NativeWindow.isSupported;
从文件中:

空气剖面图支持:此功能是 支持所有桌面操作系统 系统,但在上不受支持 移动设备或电视设备的AIR。 您可以在运行时测试支持 在桌面设备上使用 NativeWindow.isSupported属性。看见 AIR Profile支持更多信息 有关API支持的信息 跨多个配置文件

更新3:

在BlackBerry PlayBook模拟器上测试时,支持NativeWindow。我还没有在设备上测试过这一点,以了解模拟器是否支持它。此后,我开始使用以下方法来确定移动和桌面配置文件之间的差异:

if  (
    (Capabilities.os.toLowerCase().indexOf("mac") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("windows") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("linux") == -1)
    )
    deviceIsMobile = true;
这将为不同的配置文件指定设备功能。由于
cacheAsBitmapMatrix
没有列出可用性getter,您需要自己检查一次。使用try/catch块必须很容易

编辑:我将尝试说明我在“检查一次”下的意思:


获取当前配置文件可能是更干净的解决方案,但我不知道如何做到这一点。另一个“想法”:使用上面的文档,测试功能并从结果中推断配置文件,如:)

用于运行时检查应用程序是否在移动或web上,您也可以使用“capabilities.playerType”


我已经使用try/catch更新了我的问题。它可以工作,但这就是你的建议吗?如果playerType设置为“桌面”,则可能意味着移动或桌面上的AIR。
public class Capabilities2
{
    private static var cacheAsBitmapMatrixChecked:Boolean;
    private static var cacheAsBitmapMatrixStatus:Boolean;

    public static function get cacheAsBitmapMatrixIsSupported():Boolean
    {
        if (cacheAsBitmapMatrixChecked) return cacheAsBitmapMatrixStatus;
        var test:Sprite = new Sprite();
        try
        {
            text.cacheAsBitmapMatrix = new Matrix();
            cacheAsBitmapMatrixStatus = true;
        }
        catch (error:Error)
        {
            cacheAsBitmapMatrixStatus = false;
        }
        cacheAsBitmapMatrixChecked = true;
        return cacheAsBitmapMatrixStatus;
    }
}
if (Capabilities.playerType == "Desktop") {
    trace ("running on mobile");                
}
else {
    trace ("running on web");
}