Flash / Flex / ActionScript/Development/system.Capabilities
Содержание
- 1 Capable of receiving streaming video: use the flash.system.Capabilities.hasStreamingVideo property.
- 2 Checking the Player Type: Use the flash.system.Capabilities.playerType property.
- 3 Checking the System Language: Use the flash.system.Capabilities.language property and the flash.system.IME class.
- 4 Check the property flash.system.Capabilities.hasEbeddedVideo to ensure that the user can view this content before initiating this download.
- 5 Detecting Audio Capabilities
- 6 Detecting Display Settings: Use the screenResolutionX and screenResolutionY properties of the system.capabilities object.
- 7 Detecting the Operating System: Use the flash.system.Capabilities.os property.
- 8 flash.system.IME.enabled property is actually writable, so you can use it to turn on the IME.
- 9 Load different content based on the dimensions of a cellphone screen and a typical desktop computer display
- 10 Load movies based on the language code.
- 11 Test for MP3 capabilities using the flash.system.Capabilities.hasMP3 property
- 12 The flash.system.Capabilities.hasAudio property returns true if the user"s system has audio capabilities and false otherwise.
- 13 The flash.system.IME.enabled property tells you whether the user is using the IME or entering text straight from the keyboard.
- 14 To detect if the user"s system has an IME: flash.system.Capabilities.hasIME
- 15 Use flash.system.Capabilities.language property to dynamically load content in the appropriate language
- 16 Use the screen resolution values to center a pop-up browser window
- 17 Video encoding: flash.system.Capabilities.hasVideoEncoder property.
Capable of receiving streaming video: use the flash.system.Capabilities.hasStreamingVideo property.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
if(flash.system.Capabilities.hasStreamingVideo) {
trace("Code to set up a video stream and start streaming a specific video");
}
else if(flash.system.Capabilities.hasEmbeddedVideo) {
trace("Code to load an external .swf containing an embedded video");
}
else {
trace(Alternate content without any video);
}
}
}
}
Checking the Player Type: Use the flash.system.Capabilities.playerType property.
Possible values are PlugIn, ActiveX, StandAlone, and External.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
if(flash.system.Capabilities.playerType == "Plugin") {
trace("do actions for Mozilla, etc. browsers");
}
else if(flash.system.Capabilities.playerType == "ActiveX") {
trace("do actions for IE");
}
else {
trace("do actions for no browser");
}
}
}
}
Checking the System Language: Use the flash.system.Capabilities.language property and the flash.system.IME class.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.Capabilities.language);
}
}
}
Check the property flash.system.Capabilities.hasEbeddedVideo to ensure that the user can view this content before initiating this download.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
if(flash.system.Capabilities.hasStreamingVideo) {
trace("Code to set up a video stream and start streaming a specific video");
}
else if(flash.system.Capabilities.hasEmbeddedVideo) {
trace("Code to load an external .swf containing an embedded video");
}
else {
trace("Alternate content without any video");
}
}
}
}
Detecting Audio Capabilities
package {
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite {
public function Main() {
if (Capabilities.hasAudio) {
trace ("Audio OK!");
} else {
trace("Audio not available");
}
if (Capabilities.hasStreamingAudio) {
trace ("Streaming OK!");
} else {
trace("Streaming not available");
}
}
}
}
Detecting Display Settings: Use the screenResolutionX and screenResolutionY properties of the system.capabilities object.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.Capabilities.screenResolutionX);
trace(flash.system.Capabilities.screenResolutionY);
}
}
}
Detecting the Operating System: Use the flash.system.Capabilities.os property.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
var os:String = flash.system.Capabilities.os.substr(0, 3);
if (os == "Win") {
trace("Windows-specific code goes here");
} else if (os == "Mac") {
trace("Mac-specific code goes here");
} else {
trace("Must be Unix or Linux");
}
}
}
}
flash.system.IME.enabled property is actually writable, so you can use it to turn on the IME.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
flash.system.IME.enabled = false;
}
}
}
Load different content based on the dimensions of a cellphone screen and a typical desktop computer display
package{
import flash.display.Sprite;
import flash.system.Capabilities;
import flash.net.*;
public class Main extends Sprite{
public function Main(){
var resX:int = flash.system.Capabilities.screenResolutionX;
var resY:int = flash.system.Capabilities.screenResolutionY;
if ( (resX <= 240) && (resY <= 320) ) {
var url:String = "main_pocketPC.swf";
}else {
var url:String = "main_desktop.swf";
}
trace(new URLRequest(url));
}
}
}
Load movies based on the language code.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
var lang:String = flash.system.Capabilities.language.substr(0, 2);
var supportedLanguages:Array = ["en", "es", "fr"];
var useLang:String = "en";
for (var i:int = 0; i < supportedLanguages.length; i++) {
if (supportedLanguages[i] == lang) {
useLang = lang;
break;
}
}
var movieURL:String = "myMovie_" + useLang + ".swf";
trace(movieURL);
}
}
}
Test for MP3 capabilities using the flash.system.Capabilities.hasMP3 property
package{
import flash.display.Sprite;
import flash.system.Capabilities;
import flash.net.*;
import flash.media.*;
public class Main extends Sprite{
public function Main(){
if (flash.system.Capabilities.hasMP3) {
var url:URLRequest = new URLRequest("sound.mp3");
var sound:Sound = new Sound(url);
sound.play( );
} else {
// code to load an external .swf containing a ADCP sound
}
}
}
}
The flash.system.Capabilities.hasAudio property returns true if the user"s system has audio capabilities and false otherwise.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
// Load a .swf containing sound only if the Player can play audio
var content:String;
if (flash.system.Capabilities.hasAudio) {
content = "sound.swf";
} else {
content = "silent.swf";
}
}
}
}
The flash.system.IME.enabled property tells you whether the user is using the IME or entering text straight from the keyboard.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.IME.enabled);
}
}
}
To detect if the user"s system has an IME: flash.system.Capabilities.hasIME
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
trace(flash.system.Capabilities.hasIME);
}
}
}
Use flash.system.Capabilities.language property to dynamically load content in the appropriate language
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
var greetings:Array = new Array( );
greetings["en"] = "Hello";
greetings["es"] = "Hola";
greetings["fr"] = "Bonjour";
var lang:String = flash.system.Capabilities.language.substr(0, 2);
if (greetings[lang] == undefined) {
lang = "en";
}
trace(greetings[lang]);
}
}
}
Use the screen resolution values to center a pop-up browser window
package{
import flash.display.Sprite;
import flash.system.Capabilities;
import flash.net.*;
public class Main extends Sprite{
public function Main(){
var resX:int = flash.system.Capabilities.screenResolutionX;
var resY:int = flash.system.Capabilities.screenResolutionY;
var winW:int = 200;
var winH:int = 200;
var winX:int = (resX / 2) - (winW / 2);
var winY:int = (resY / 2) - (winH / 2);
var jsCode:String = "javascript:void(newWin=window.open("http://www.wbex.ru/"," +
""newWindow", "width=" + winW +
", height=" + winH + "," +
"left=" + winX + ",top=" + winY + ""));";
}
}
}
Video encoding: flash.system.Capabilities.hasVideoEncoder property.
package{
import flash.display.Sprite;
import flash.system.Capabilities;
public class Main extends Sprite{
public function Main(){
if(flash.system.Capabilities.hasVideoEncoder) {
trace("hasVideoEncoder");
} else {
trace("else");
}
}
}
}