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

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
  getDefinition(name:String):Object
指定されたアプリケーションドメインから一般定義を取得します。
ApplicationDomain
  hasDefinition(name:String):Boolean
指定されたアプリケーションドメイン内に一般定義が存在するかどうかを確認します。
ApplicationDomain
 InheritedhasOwnProperty(name:String):Boolean
オブジェクトに指定されたプロパティが定義されているかどうかを示します。
Object
 InheritedisPrototypeOf(theClass:Object):Boolean
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
Object
 InheritedpropertyIsEnumerable(name:String):Boolean
指定されたプロパティが存在し、列挙可能かどうかを示します。
Object
 InheritedsetPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
ループ処理に対するダイナミックプロパティの可用性を設定します。
Object
 InheritedtoString():String
指定されたオブジェクトのストリング表現を返します。
Object
 InheritedvalueOf():Object
指定されたオブジェクトのプリミティブ値を返します。
Object
プロパティの詳細
currentDomainプロパティ
currentDomain:ApplicationDomain  [read-only]

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

実装
    public static function get currentDomain():ApplicationDomain

関連項目

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

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

実装
    public function get parentDomain():ApplicationDomain

関連項目

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

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

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

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

パラメータ
name:String — 定義の名前。

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

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

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

パラメータ
name:String — 定義の名前。

戻り値
Boolean — 指定された定義が存在する場合は true を返します。含まれない場合は false を返します。

次の例では、実行時のクラスのロードを示します。

メモ :

最初に、以下のコードから RuntimeClasses.swf ファイルを作成します。

  package {
  import flash.display.Sprite;
       
      public class RuntimeClasses extends Sprite {
          public function RuntimeClasses() {
           }        
       }
   }
   
  import flash.display.Sprite;
  import flash.text.TextField;
   
  class Greeter {
      private var greeting:String;
      
      public function Greeter() {
          greeting = "Hello World";
       }
       
      public function greet():String {
          return greeting;
       }
   }
   
  class VisualGreeter extends Sprite {
      private var greeting:String;
      private var txt:TextField;
            
      public function VisualGreeter() {
          greeting = "Hello World";
          txt = new TextField();
          txt.text = greeting;
          txt.background = true;
          txt.backgroundColor = 0xFF0000;
       }
            
      public function greet():String {
          addChild(txt);
          return txt.text
       }
  }
  

次に、以下のコードを実装します。



package {
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.errors.IllegalOperationError;
    import flash.events.Event;

    public class ApplicationDomainExample extends Sprite {
        private var loader:ClassLoader;
        
        public function ApplicationDomainExample() {
            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 {
            throw new IllegalOperationError("Cannot load the specified file.");
        }
        
        private function classLoadedHandler(e:Event):void {
            var greeterClassRef:Class = loader.getClass("Greeter");
            var greeter:Object = new greeterClassRef();
            trace(greeter.greet()); // Hello World
            
            greeterClassRef = loader.getClass("VisualGreeter");
            greeter = new greeterClassRef();
            addChild(DisplayObject(greeter));
            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));
    }
}




 

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

現在のページ: http://livedocs.adobe.com/flex/2_jp/langref/flash/system/ApplicationDomain.html