gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:32:33 25 4
gpt4 key购买 nike

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

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

像下面这样的东西是理想的:

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 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.

更新 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;

最佳答案

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

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

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

获取当前配置文件可能是更简洁的解决方案,但我不知道该怎么做。另一个“想法”:使用上面的文档,测试功能并从结果中推断出配置文件,如 Einstein riddle :)

关于actionscript-3 - ActionScript/AIR - 在运行时确定设备配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5367401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com