パッケージflash.system
クラスpublic final class ApplicationDomain
継承ApplicationDomain Inheritance Object

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

ApplicationDomain クラスは、クラス定義の個別のグループのコンテナです。アプリケーションドメインは、同じセキュリティドメイン内にあるクラスを分割するために使用されます。同じクラスの複数の定義が存在すること、および子が親の定義を再利用することが可能になります。

アプリケーションドメインは、外部 SWF ファイルが Loader クラスによってロードされる場合に使用されます。ロードされる SWF ファイルのすべての ActionScript 3.0 定義は、アプリケーションドメインに保存されます。アプリケーションドメインは、Loader オブジェクトの load() または loadBytes() メソッドの context パラメータとして渡す LoaderContext オブジェクトの applicationDomain プロパティによって指定されます。LoaderInfo オブジェクトにも applicationDomain プロパティがあります。これは読み取り専用です。

SWF ファイル内のすべてのコードは、アプリケーションドメイン内に存在するように定義されます。現在のアプリケーションドメインは、メインアプリケーションが実行されている場所です。現在のドメインなど、すべてのアプリケーションドメインは、システムドメインに含まれます。つまり、システムドメインにはすべての Flash Player クラスが含まれます。

システムドメインを除くすべてのアプリケーションドメインには、親ドメインが関連付けられます。メインアプリケーションのアプリケーションドメインに対する親ドメインは、システムドメインです。ロードされるクラスは、その親によってまだ定義されていない場合にのみ定義されます。ロードされるクラスの定義を新しい定義でオーバーライドすることはできません。

アプリケーションドメインの使用例については、『ActionScript 3.0 のプログラミング』を参照してください。

ApplicationDomain() コンストラクタ関数を使用すると、ApplicationDomain オブジェクトを作成できます。

例を表示

関連項目

flash.display.Loader.load()
flash.display.Loader.loadBytes()
flash.display.LoaderInfo
flash.net.URLRequest
flash.system.LoaderContext
ApplicationDomain クラスの使用


パブリック プロパティ
 プロパティ定義元
 Inheritedconstructor : Object
特定のオブジェクトインスタンスのクラスオブジェクトまたはコンストラクタ関数への参照です。
Object
  currentDomain : ApplicationDomain
[static] [read-only] コードが実行されている現在のアプリケーションドメインを取得します。
ApplicationDomain
  parentDomain : ApplicationDomain
[read-only] このアプリケーションドメインの親ドメインを取得します。
ApplicationDomain
 Inheritedprototype : Object
[static] クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
Object
パブリック メソッド
 メソッド定義元
  
ApplicationDomain(parentDomain:ApplicationDomain = null)
新しいアプリケーションドメインを作成します。
ApplicationDomain
  
指定されたアプリケーションドメインから一般定義を取得します。
ApplicationDomain
  
指定されたアプリケーションドメイン内に一般定義が存在するかどうかを確認します。
ApplicationDomain
 Inherited
オブジェクトに指定されたプロパティが定義されているかどうかを示します。
Object
 Inherited
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 Inherited
指定されたプロパティが存在し列挙できるかどうかを示します。
Object
 Inherited
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
 Inherited
指定されたオブジェクトのストリング表現を返します。
Object
 Inherited
指定されたオブジェクトのプリミティブな値を返します。
Object
プロパティの詳細
currentDomainプロパティ
currentDomain:ApplicationDomain  [read-only]

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

コードが実行されている現在のアプリケーションドメインを取得します。


実装
    public static function get currentDomain():ApplicationDomain

関連項目

parentDomainプロパティ 
parentDomain:ApplicationDomain  [read-only]

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

このアプリケーションドメインの親ドメインを取得します。


実装
    public function get parentDomain():ApplicationDomain

関連項目

コンストラクタの詳細
ApplicationDomain()コンストラクタ
public function ApplicationDomain(parentDomain:ApplicationDomain = null)

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

新しいアプリケーションドメインを作成します。

パラメータ
parentDomain:ApplicationDomain (default = null) — 親ドメインが渡されない場合、このアプリケーションドメインはシステムドメインを親ドメインとします。
メソッドの詳細
getDefinition()メソッド
public function getDefinition(name:String):Object

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

指定されたアプリケーションドメインから一般定義を取得します。定義には、クラス、名前空間、または関数の定義があります。

パラメータ

name:String — 定義の名前。

戻り値
Object — 定義に関連付けられたオブジェクト。

例外
ReferenceError — 指定された名前の一般定義は存在しません。
hasDefinition()メソッド 
public function hasDefinition(name:String):Boolean

言語バージョン : ActionScript 3.0
Player のバージョン : Flash Player 9

指定されたアプリケーションドメイン内に一般定義が存在するかどうかを確認します。定義には、クラス、名前空間、または関数の定義があります。

パラメータ

name:String — 定義の名前。

戻り値
Boolean — 指定された定義が存在する場合は true を返します。含まれない場合は false を返します。
例の使用法
ApplicationDomainExample.as

次の例では、実行時のクラスのロードと、別の SWF に存在するクラスのパブリックメソッドの呼び出し方法を示します。

メモ :

最初に、以下のコードから "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));
    }
}
ApplicationDomainExample.2.as

複数の SWF ファイルに同じ名前だが異なる実装を提供するコンパイル済みクラスが含まれている場合、次の例に従って、外部からロードする SWF ファイルのクラスをそれぞれのクラスと分割できます。以前の例では、子 SWF が 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));
    }
}




 

このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート

現在のページ: http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/system/ApplicationDomain.html