为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
We need to detect the environment that our app runs on so that we can change the UI accordingly. For example, we'll show system menu on AIR but not in browser:
if(SystemUtils.isAirEnvironment()) {
// show menu
}
Implementation:
package com.insprise.common
{
import flash.utils.getDefinitionByName;
/**
* Provides system utilities.
*/
public class SystemUtils
{
private static var _environment:int = 0;
public static const ENV_AIR:int = 2;
public static const ENV_BROWSER:int = 1;
/**
* Checks whether the application is running on AIR.
*/
public static function isAirEnvironment():Boolean {
if(_environment == 0) { // detect.
_environment = ENV_BROWSER; // default.
try {
if(getDefinitionByName("mx.core.WindowedApplication") != null) {
_environment = ENV_AIR;
}
}catch(e:Error) {
// possible ReferenceError, ignore.
}
}
return _environment == ENV_AIR;
}
/**
* Checks whether the application is running in browser.
*/
public static function isBrowserEnvironment():Boolean {
return ! isAirEnvironment();
}
} // end class
} // end package