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.
<source lang="java">
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); } } }
}
</source>
Checking the Player Type: Use the flash.system.Capabilities.playerType property.
<source lang="java">
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"); } } }
}
</source>
Checking the System Language: Use the flash.system.Capabilities.language property and the flash.system.IME class.
<source lang="java">
package{
import flash.display.Sprite; import flash.system.Capabilities; public class Main extends Sprite{ public function Main(){ trace(flash.system.Capabilities.language); } }
}
</source>
Check the property flash.system.Capabilities.hasEbeddedVideo to ensure that the user can view this content before initiating this download.
<source lang="java">
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"); } } }
}
</source>
Detecting Audio Capabilities
<source lang="java">
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"); } } }
}
</source>
Detecting Display Settings: Use the screenResolutionX and screenResolutionY properties of the system.capabilities object.
<source lang="java">
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); } }
}
</source>
Detecting the Operating System: Use the flash.system.Capabilities.os property.
<source lang="java">
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"); } } }
}
</source>
flash.system.IME.enabled property is actually writable, so you can use it to turn on the IME.
<source lang="java">
package{
import flash.display.Sprite; import flash.system.Capabilities; public class Main extends Sprite{ public function Main(){ flash.system.IME.enabled = false; } }
}
</source>
Load different content based on the dimensions of a cellphone screen and a typical desktop computer display
<source lang="java">
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)); } }
}
</source>
Load movies based on the language code.
<source lang="java">
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); } }
}
</source>
Test for MP3 capabilities using the flash.system.Capabilities.hasMP3 property
<source lang="java">
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 } } }
}
</source>
The flash.system.Capabilities.hasAudio property returns true if the user"s system has audio capabilities and false otherwise.
<source lang="java">
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"; } } }
}
</source>
The flash.system.IME.enabled property tells you whether the user is using the IME or entering text straight from the keyboard.
<source lang="java">
package{
import flash.display.Sprite; import flash.system.Capabilities; public class Main extends Sprite{ public function Main(){ trace(flash.system.IME.enabled); } }
}
</source>
To detect if the user"s system has an IME: flash.system.Capabilities.hasIME
<source lang="java">
package{
import flash.display.Sprite; import flash.system.Capabilities; public class Main extends Sprite{ public function Main(){ trace(flash.system.Capabilities.hasIME); } }
}
</source>
Use flash.system.Capabilities.language property to dynamically load content in the appropriate language
<source lang="java">
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]); } }
}
</source>
Use the screen resolution values to center a pop-up browser window
<source lang="java">
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 + ""));"; } }
}
</source>
Video encoding: flash.system.Capabilities.hasVideoEncoder property.
<source lang="java">
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"); } } }
}
</source>