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

发布于 2024-10-23 21:56:05 字数 1743 浏览 8 评论 0原文

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

我想在我的一些显示对象上使用 cacheAsBitmapMatrix,但如果 cacheAsBitmapMatrix 包含在设备配置文件不是 mobileDevice 或扩展移动设备

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

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;

运行时的配置文件是从 flash .display.NativeWindow 文档:

AIR 配置文件支持:此功能是 所有桌面操作系统均支持 系统,但不支持 移动设备或 AIR for TV 设备。 您可以在运行时测试支持 在桌面设备上使用 NativeWindow.isSupported 属性。看 AIR 配置文件支持更多 有关 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;

i'm developing an application for both desktop and mobile devices and would like to use the same code base for each build.

i want to employ cacheAsBitmapMatrix on some of my display objects, but cacheAsBitmapMatrix throws an error if it's included in an AIR application with a device profile other than mobileDevice or extendedMobileDevice.

something like the following would be ideal:

if (cacheAsBitmapMatrix.isSupported)
   myDisplayObject.cacheAsBitmapMatrix = new Matrix();

update using try/catch:

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

update:

except for television profiles, this should work as well to distinguish between mobile and desktop:

//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");

update 2:

it seems the easiest way, and perhaps the most common way to determine the profile at runtime is to call:

NativeWindow.isSupported;

from the flash.display.NativeWindow documentation:

AIR profile support: This feature is
supported on all desktop operating
systems, but is not supported on
mobile devices or AIR for TV devices.
You can test for support at run time
on desktop devices using the
NativeWindow.isSupported property. See
AIR Profile Support for more
information regarding API support
across multiple profiles.

update 3:

while testing this on the BlackBerry PlayBook simulator, NativeWindow was supported. i haven't tested this on the device to know if it's was just supported on the simulator or not. i've since started using the following to determine the difference between mobile and desktop profiles:

if  (
    (Capabilities.os.toLowerCase().indexOf("mac") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("windows") == -1) &&
    (Capabilities.os.toLowerCase().indexOf("linux") == -1)
    )
    deviceIsMobile = true;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫罗兰の梦幻 2024-10-30 21:56:05

文档指定了不同配置文件的设备功能。由于 cacheAsBitmapMatrix 没有列出可用性 getter,因此您需要自己检查一次。使用 try/catch 块一定很容易做到。

编辑:我将尝试说明“检查一次”下的含义:

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;
    }
}

获取当前配置文件可能是更清晰的解决方案,但我不知道该怎么做。另一个“想法”:使用上面的文档,测试功能并从结果中推断出轮廓,就像 爱因斯坦之谜 :)

This document specifies device capabilities for different profiles. Since cacheAsBitmapMatrix has no availability getter listed, you'll need to check it yourself once. It must be easy to do with try/catch block.

Edit: I'll try to illustrate what I meant under "check once":

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;
    }
}

Get current profile might be cleaner solution, but I don't know how to do it. Another 'idea': using document above, test capabilities and deduce profile from results, like in Einstein riddle :)

遥远的绿洲 2024-10-30 21:56:05

对于运行时检查您的应用程序是在移动设备上还是在网络上,您还可以使用“Capability.playerType”

if (Capabilities.playerType == "Desktop") {
    trace ("running on mobile");                
}
else {
    trace ("running on web");
}

For runtime checking if your application is on mobile or on web you can also use "Capabilities.playerType"

if (Capabilities.playerType == "Desktop") {
    trace ("running on mobile");                
}
else {
    trace ("running on web");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文