ASCB阅读笔记三、Runtime Environment

1,检测用户浏览器安装的Flash Player版本
http://www.adobe.com/software/flashplayer/download/detection_kit
比较搞笑的是ActionScript 3.0有一个flash.system.Capabilities.version属性用来检测Flash Player版本,但是它不能在
Flash Player 8.5之前版本工作,所以这对Flash检测毫无用武之地。

2,检测操作系统

package {
  import flash.display.Sprite;
  import flash.system.Capabilities;

  public class Test extends Sprite {
    public function Test() {
      var os:String = Capabilities.os.substr(0, 3);
      if (os == "Win") {
        // Windows-specific code goes here
      } else if (os == "Mac") {
        // Mac-specific code goes here
      } else {
        // Must be Unix or Linux
      }
    }
  }
}


3,检测Player类型
if(flash.system.Capabilities.playerType == "Plugin") {
  // do actions for Mozilla, etc. browsers
} else if(flash.system.Capabilities.playerType == "ActiveX") {
  // do actions for IE
} else {
  // do actions for no browser
}


4,检测系统语言
var greetings:Array = new Array(  );
greetings["en"] = "Hello";
greetings["es"] = "Hola";
greetings["fr"] = "Bonjour";

// Extract the first two characters from the language code.
var lang:String = flash.system.Capabilities.language.substr(0, 2);

// Use a default language if the language is not in the list
if (greetings[lang] == undefined) {
  lang = "en";
}

// Display the greeting in the appropriate language.
trace(greetings[lang]);


5,检测IME
flash.system.Capabilities.hasIME
flash.system.IME.enabled
flash.system.IME


6,检测分辨率
var resX:int = flash.system.Capabilities.screenResolutionX;
var resY:int = flash.system.Capabilities.screenResolutionY;

// If the resolution is 240 x 320 or less, then load the PocketPC
// movie version. Otherwise, assume the device is a desktop computer 
// and load the regular content.
if ( (resX <= 240) && (resY <= 320) ) {
  var url:String = "main_pocketPC.swf";
}
else {
  var url:String = "main_desktop.swf";
}
loader.load(new URLRequest(url));


7,设置Movie的Scale模式
stage.scaleMode = flash.display.StageScaleMode.SHOW_ALL
stage.scaleMode = flash.display.StageScaleMode.NO_BORDER
stage.scaleMode = flash.display.StageScaleMode.EXACT_FIT
stage.scaleMode = flash.display.StageScaleMode.NO_SCALE


8,设置Movie在Player里的位置
stage.align = flash.display.StageAlign.TOP
stage.align = flash.display.StageAlign.BOTTOM
stage.align = flash.display.StageAlign.LEFT
stage.align = flash.display.StageAlign.RIGHT
stage.align = flash.display.StageAlign.TOP_LEFT
stage.align = flash.display.StageAlign.TOP_RIGHT
stage.align = flash.display.StageAlign.BOTTON_LEFT
stage.align = flash.display.StageAlign.BOTTON_RIGHT


9,隐藏Flash Player的右键点击菜单项
stage.showDefaultContextMenu = false;

但是这只能部分隐藏

10,检测音频
flash.system.Capabilities.hasAudio
flash.system.Capabilities.hasMP3


11,检测视频
flash.system.Capabilities.hasEmbeddedVideo
flash.system.Capabilities.hasStreamingVideo
flash.system.Capabilities.hasVideoEncoder


12,提示用户修改Flash Player设置
flash.system.Security.showSettings(flash.system.SecurityPanel.CAMERA);
flash.system.Security.showSettings(flash.system.SecurityPanel.DEFAULT);
flash.system.Security.showSettings(flash.system.SecurityPanel.LOCAL_STORAGE);
flash.system.Security.showSettings(flash.system.SecurityPanel.MICROPHONE);
flash.system.Security.showSettings(flash.system.SecurityPanel.PRIVACY);
flash.system.Security.showSettings(flash.system.SecurityPanel.SETTINGS_MANAGER);


13,处理系统安全
当我们从另一个domain加载一个.swf文件到当前程序中时,我们可能想运行它访问本程序的ActionScript
flash.system.Security.allowDomain()
flash.system.Security.allowInsecureDomain()
flash.system.Security.loadPolicyFile()

<?xml version="1.0"?>
<!-- http://www.mydomain.com/crossdomain.xml -->
<cross-domain-policy>
  <allow-access-from domain="www.otherdomain.com" />
  <allow-access-from domain="*.adobe.com" />
  <allow-access-from domain="123.45.67.89" />
</cross-domain-policy>

// wildcards
<allow-access-from domain="*" />

// deny access to any domain except the current one
<cross-domain-policy>
</cross-domain-policy>

你可能感兴趣的:(linux,OS,Security,Flash,actionscript)