| パッケージ | flash.system |
| クラス | public final class ApplicationDomain |
| 継承 | ApplicationDomain Object |
| 言語バージョン : | ActionScript 3.0 |
| Player のバージョン : | 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
[static] [read-only]
コードが実行されている現在のアプリケーションドメインを取得します。
| ApplicationDomain | ||
| parentDomain : ApplicationDomain
[read-only]
このアプリケーションドメインの親ドメインを取得します。
| ApplicationDomain | ||
![]() | prototype : Object
[static]
クラスまたは関数オブジェクトのプロトタイプオブジェクトへの参照です。
| Object | |
| メソッド | 定義元 | ||
|---|---|---|---|
|
ApplicationDomain(parentDomain:ApplicationDomain = null)
新しいアプリケーションドメインを作成します。
| ApplicationDomain | ||
|
指定されたアプリケーションドメインから一般定義を取得します。
| ApplicationDomain | ||
|
指定されたアプリケーションドメイン内に一般定義が存在するかどうかを確認します。
| ApplicationDomain | ||
![]() |
オブジェクトに指定されたプロパティが定義されているかどうかを示します。
| Object | |
![]() |
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
| Object | |
![]() |
指定されたプロパティが存在し列挙できるかどうかを示します。
| Object | |
![]() |
ループ処理に対するダイナミックプロパティの可用性を設定します。
| Object | |
![]() |
指定されたオブジェクトのストリング表現を返します。
| Object | |
![]() |
指定されたオブジェクトのプリミティブな値を返します。
| 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 を返します。
|
メモ :
最初に、以下のコードから "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));
}
}
このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート
現在のページ: http://livedocs.adobe.com/flash/9.0_jp/ActionScriptLangRefV3/flash/system/ApplicationDomain.html