| パッケージ | flash.system |
| クラス | public final class ApplicationDomain |
| 継承 | ApplicationDomain Object |
| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
アプリケーションドメインは、外部 SWF ファイルが Loader クラスによって読み込まれる場合に使用されます。読み込まれる SWF ファイルのすべての ActionScript 3.0 定義は、アプリケーションドメインに保存されます。アプリケーションドメインは、Loader オブジェクトの load() または loadBytes() メソッドの context パラメータとして渡す LoaderContext オブジェクトの applicationDomain プロパティによって指定されます。LoaderInfo オブジェクトにも applicationDomain プロパティがあります。これは読み取り専用です。
SWF ファイル内のすべてのコードは、アプリケーションドメイン内に存在するように定義されます。現在のアプリケーションドメインは、メインアプリケーションが実行されている場所です。現在のドメインを含むすべてのアプリケーションドメインはシステムドメインに属します。つまり、システムドメインにはすべての Flash Player クラスが含まれます。
システムドメインを除くすべてのアプリケーションドメインには、親ドメインが関連付けられます。メインアプリケーションのアプリケーションドメインに対する親ドメインは、システムドメインです。読み込まれるクラスは、その親によってまだ定義されていない場合にのみ定義されます。読み込まれるクラスの定義を新しい定義でオーバーライドすることはできません。
アプリケーションドメインの使用例については、『ActionScript 3.0 のプログラミング』を参照してください。
ApplicationDomain() コンストラクタ関数を使用すると、ApplicationDomain オブジェクトを作成できます。
関連項目
| プロパティ | 定義元 | ||
|---|---|---|---|
![]() | constructor : Object 指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。 | Object | |
| currentDomain : ApplicationDomain [静的] [読み取り専用] コードが実行されている現在のアプリケーションドメインを取得します。 | ApplicationDomain | ||
| domainMemory : ByteArray この ApplicationDomain 内でドメイン全般のメモリ処理が実行されるオブジェクトを取得して設定します。 | ApplicationDomain | ||
| MIN_DOMAIN_MEMORY_LENGTH : uint [静的] [読み取り専用] ApplicationDomain.domainMemory として使用するために必要なメモリオブジェクトの最小の長さを取得します。 | ApplicationDomain | ||
| parentDomain : ApplicationDomain [読み取り専用] このアプリケーションドメインの親ドメインを取得します。 | ApplicationDomain | ||
![]() | prototype : Object [静的] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。 | Object | |
| メソッド | 定義元 | ||
|---|---|---|---|
ApplicationDomain(parentDomain:ApplicationDomain = null) 新しいアプリケーションドメインを作成します。 | ApplicationDomain | ||
指定されたアプリケーションドメインから公開定義を取得します。 | ApplicationDomain | ||
指定されたアプリケーションドメイン内に公開定義が存在するかどうかを確認します。 | ApplicationDomain | ||
![]() | オブジェクトに指定されたプロパティが定義されているかどうかを示します。 | Object | |
![]() | Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。 | Object | |
![]() | 指定されたプロパティが存在し、列挙できるかどうかを示します。 | Object | |
![]() | ループ処理に対するダイナミックプロパティの可用性を設定します。 | Object | |
![]() | 指定されたオブジェクトのストリング表現を返します。 | Object | |
![]() | 指定されたオブジェクトのプリミティブな値を返します。 | Object | |
| currentDomain | プロパティ |
currentDomain:ApplicationDomain [読み取り専用] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
コードが実行されている現在のアプリケーションドメインを取得します。
public static function get currentDomain():ApplicationDomain関連項目
| domainMemory | プロパティ |
domainMemory:ByteArray [読み書き可能] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 10, AIR 1.5 |
この ApplicationDomain 内でドメイン全般のメモリ処理が実行されるオブジェクトを取得して設定します。
public function get domainMemory():ByteArray public function set domainMemory(value:ByteArray):void| MIN_DOMAIN_MEMORY_LENGTH | プロパティ |
MIN_DOMAIN_MEMORY_LENGTH:uint [読み取り専用] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 10, AIR 1.5 |
ApplicationDomain.domainMemory として使用するために必要なメモリオブジェクトの最小の長さを取得します。
public static function get MIN_DOMAIN_MEMORY_LENGTH():uint| parentDomain | プロパティ |
parentDomain:ApplicationDomain [読み取り専用] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
このアプリケーションドメインの親ドメインを取得します。
public function get parentDomain():ApplicationDomain関連項目
| ApplicationDomain | () | コンストラクタ |
public function ApplicationDomain(parentDomain:ApplicationDomain = null)| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
新しいアプリケーションドメインを作成します。
パラメータparentDomain:ApplicationDomain (default = null) — 親ドメインが渡されない場合、このアプリケーションドメインはシステムドメインを親ドメインとします。 |
| getDefinition | () | メソッド |
public function getDefinition(name:String):Object| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
指定されたアプリケーションドメインから公開定義を取得します。定義には、クラス、名前空間、または関数の定義があります。
パラメータ
name:String — 定義の名前です。 |
Object — 定義に関連付けられたオブジェクトです。 |
ReferenceError — 指定された名前の公開定義は存在しません。 |
| hasDefinition | () | メソッド |
public function hasDefinition(name:String):Boolean| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0 Flash Player 9 |
指定されたアプリケーションドメイン内に公開定義が存在するかどうかを確認します。定義には、クラス、名前空間、または関数の定義があります。
パラメータ
name:String — 定義の名前です。 |
Boolean —
指定された定義が存在する場合は true を返します。含まれない場合は false を返します。
|
注意:
最初に、以下のコードから "RuntimeClasses.swf" ファイルを作成します。
package {
import flash.display.Sprite;
public class RuntimeClasses extends Sprite
{
public function RuntimeClasses()
{}
public function greet():String {
return("Hello World");
}
}
}次に、以下のコードを実装します。
package {
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.text.TextField;
public class ApplicationDomainExample extends Sprite {
private var loader:ClassLoader;
private var tf:TextField = new TextField();
public function ApplicationDomainExample() {
addChild(tf);
loader = new ClassLoader();
loader.addEventListener(ClassLoader.LOAD_ERROR,loadErrorHandler);
loader.addEventListener(ClassLoader.CLASS_LOADED,classLoadedHandler);
loader.load("RuntimeClasses.swf");
}
private function loadErrorHandler(e:Event):void {
tf.text = "Load failed";
throw new IllegalOperationError("Cannot load the specified file.");
}
private function classLoadedHandler(e:Event):void {
var runtimeClassRef:Class = loader.getClass("RuntimeClasses");
var greeter:Object = new runtimeClassRef();
tf.text = greeter.greet();
}
}
}
import flash.display.Loader;
import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
class ClassLoader extends EventDispatcher {
public static var CLASS_LOADED:String = "classLoaded";
public static var LOAD_ERROR:String = "loadError";
private var loader:Loader;
private var swfLib:String;
private var request:URLRequest;
private var loadedClass:Class;
public function ClassLoader() {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
}
public function load(lib:String):void {
swfLib = lib;
request = new URLRequest(swfLib);
var context:LoaderContext = new LoaderContext();
context.applicationDomain=ApplicationDomain.currentDomain;
loader.load(request,context);
}
public function getClass(className:String):Class {
try {
return loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class;
} catch (e:Error) {
throw new IllegalOperationError(className + " definition not found in " + swfLib);
}
return null;
}
private function completeHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.CLASS_LOADED));
}
private function ioErrorHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.LOAD_ERROR));
}
private function securityErrorHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.LOAD_ERROR));
}
}ApplicationDomain.currentDomain を使用するように指示されました。 今回は、新しい ApplicationDomain が作成されます。これにより、2 番目に読み込まれる任意の SWF の Greeter クラスのプロパティおよびメソッドが、最初の Greeter クラスのプロパティおよびメソッドと置き換わることはありません。 これは、context.applicationDomain プロパティ(load メソッド)をプロパティを変更してテストできます。このメソッドは ClassLoader 内のものです。
注意:
以下のコードを使用して、Greeter.as ファイルを "en" ディレクトリに作成します。
package {
import flash.display.Sprite;
public class Greeter extends Sprite
{
public function Greeter()
{
}
public function greet():String {
return("Good Morning");
}
}
}その後、同じ Greeter.as ファイルを "es" ディレクトリに作成します。
package {
import flash.display.Sprite;
public class Greeter extends Sprite
{
public function Greeter()
{
}
public function greet():String {
return("Buenos Dias");
}
}
}両方の SWF ファイルをコンパイルし、以下のコードを実装します。
package {
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class ApplicationDomainExample2 extends Sprite {
private var spanishGreeterLoader:ClassLoader;
private var englishGreeterLoader:ClassLoader;
private var tf:TextField = new TextField();
private var greetersLoaded:uint = 0;
public function ApplicationDomainExample2() {
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
spanishGreeterLoader = new ClassLoader();
spanishGreeterLoader.addEventListener(ClassLoader.LOAD_ERROR,loadErrorHandler);
spanishGreeterLoader.addEventListener(ClassLoader.CLASS_LOADED,classLoadedHandler);
spanishGreeterLoader.load("es/Greeter.swf");
englishGreeterLoader = new ClassLoader();
englishGreeterLoader.addEventListener(ClassLoader.LOAD_ERROR,loadErrorHandler);
englishGreeterLoader.addEventListener(ClassLoader.CLASS_LOADED,classLoadedHandler);
englishGreeterLoader.load("en/Greeter.swf");
}
private function loadErrorHandler(e:Event):void {
tf.text = "Load failed";
throw new IllegalOperationError("Cannot load the specified file.");
}
private function classLoadedHandler(e:Event):void {
greetersLoaded++;
if(greetersLoaded == 2) {
greet();
}
}
private function greet():void {
var spanishGreeter:Class = spanishGreeterLoader.getClass("Greeter");
var englishGreeter:Class = englishGreeterLoader.getClass("Greeter");
var greeter1 = new spanishGreeter();
var greeter2 = new englishGreeter();
tf.text = greeter1.greet() + "\n" + greeter2.greet();
}
}
}
import flash.display.Loader;
import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
class ClassLoader extends EventDispatcher {
public static var CLASS_LOADED:String = "classLoaded";
public static var LOAD_ERROR:String = "loadError";
private var loader:Loader;
private var swfLib:String;
private var request:URLRequest;
private var loadedClass:Class;
public function ClassLoader() {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);
}
public function load(lib:String):void {
swfLib = lib;
request = new URLRequest(swfLib);
var context:LoaderContext = new LoaderContext();
// context.applicationDomain = ApplicationDomain.currentDomain;
context.applicationDomain = new ApplicationDomain();
loader.load(request,context);
}
public function getClass(className:String):Class {
try {
return loader.contentLoaderInfo.applicationDomain.getDefinition(className) as Class;
} catch (e:Error) {
throw new IllegalOperationError(className + " definition not found in " + swfLib);
}
return null;
}
private function completeHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.CLASS_LOADED));
}
private function ioErrorHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.LOAD_ERROR));
}
private function securityErrorHandler(e:Event):void {
dispatchEvent(new Event(ClassLoader.LOAD_ERROR));
}
}