Detect AIR versus Flash Player from an actionscript library

独自空忆成欢 提交于 2019-12-19 02:38:14

问题


I have an swc which needs to operate slightly differently depending on whether it is being hosted by AIR or not. I've seen two suggestions on the internet:

  • Test Application.application for WindowedApplication.
  • Test Security.sandboxType for Security.APPLICATION.

However, these don't seem to work in my .swc as the compiler can't find WindowedApplication or Security.APPLICATION. My library doesn't need any other AIR features so I assume it's not being linked to the AIR libraries, and I assume shouldn't be in order that it continues to work in flash player.

Any suggestions?


回答1:


You can use the flash.system.Capabilities object to find out if you running under AIR.

var isAir : Boolean = (Capabilities.playerType == "Desktop");
var isFlashPlayer : Boolean = (Capabilities.playerType == "StandAlone");
var isBrowser : Boolean = (Capabilities.playerType == "ActiveX" || Capabilities.playerType == "PlugIn");
var isOther : Boolean = (Capabilities.playerType == "External");



回答2:


I would try flash.utils.getDefinitionByName() which will allow you to pass one of the AIR API classes as a String. This should throw an error which you can catch in a Flex environment or be successful in an AIR environment.



来源:https://stackoverflow.com/questions/461923/detect-air-versus-flash-player-from-an-actionscript-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!