| パッケージ | flash.system |
| クラス | public final class ApplicationDomain |
| 継承 | ApplicationDomain Object |
| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0, Flash Player 9, Flash Lite 4 |
アプリケーションドメインは、外部 SWF ファイルが Loader クラスによってロードされる場合に使用されます。ロードされる SWF ファイルのすべての ActionScript 3.0 定義は、アプリケーションドメインに保存されます。アプリケーションドメインは、Loader オブジェクトの load() または loadBytes() メソッドの context パラメーターとして渡す LoaderContext オブジェクトの applicationDomain プロパティによって指定されます。LoaderInfo オブジェクトにも applicationDomain プロパティがあります。これは読み取り専用です。
SWF ファイル内のすべてのコードは、アプリケーションドメイン内に存在するように定義されます。現在のアプリケーションドメインは、メインアプリケーションが実行されている場所です。現在のドメインを含むすべてのアプリケーションドメインはシステムドメインに属します。つまり、システムドメインにはすべての Flash Player クラスが含まれます。
システムドメインを除くすべてのアプリケーションドメインには、親ドメインが関連付けられます。メインアプリケーションのアプリケーションドメインに対する親ドメインは、システムドメインです。ロードされるクラスは、その親によってまだ定義されていない場合にのみ定義されます。ロードされるクラスの定義を新しい定義でオーバーライドすることはできません。
アプリケーションドメインの使用例については、『ActionScript 3.0 開発ガイド』を参照してください。
ApplicationDomain() コンストラクター関数を使用すると、ApplicationDomain オブジェクトを作成できます。
さらに例を参照
関連する API エレメント
flash.display.Loader.loadBytes()
flash.display.LoaderInfo
flash.net.URLRequest
flash.system.LoaderContext
| プロパティ | 定義元 | ||
|---|---|---|---|
![]() | constructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクター関数への参照です。 | Object | |
| currentDomain : ApplicationDomain [静的] [読み取り専用]
コードが実行されている現在のアプリケーションドメインを取得します。 | ApplicationDomain | ||
| domainMemory : ByteArray
この ApplicationDomain 内でドメイン全般のメモリ処理が実行されるオブジェクトを取得して設定します。 | ApplicationDomain | ||
| MIN_DOMAIN_MEMORY_LENGTH : uint [静的] [読み取り専用]
ApplicationDomain.domainMemory として使用するために必要なメモリオブジェクトの最小の長さを取得します。 | ApplicationDomain | ||
| parentDomain : ApplicationDomain [読み取り専用]
このアプリケーションドメインの親ドメインを取得します。 | ApplicationDomain | ||
| メソッド | 定義元 | ||
|---|---|---|---|
ApplicationDomain(parentDomain:ApplicationDomain = null)
新しいアプリケーションドメインを作成します。 | ApplicationDomain | ||
指定されたアプリケーションドメインから公開定義を取得します。 | ApplicationDomain | ||
指定されたアプリケーションドメインから公開定義のすべての完全修飾名を取得します。 | ApplicationDomain | ||
指定されたアプリケーションドメイン内に公開定義が存在するかどうかを確認します。 | ApplicationDomain | ||
![]() |
オブジェクトに指定されたプロパティが定義されているかどうかを示します。 | Object | |
![]() |
Object クラスのインスタンスが、パラメーターとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。 | Object | |
![]() |
指定されたプロパティが存在し、列挙できるかどうかを示します。 | Object | |
![]() |
ループ処理に対するダイナミックプロパティの可用性を設定します。 | Object | |
![]() |
ロケール固有の規則に従って書式設定された、このオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのプリミティブな値を返します。 | Object | |
currentDomain | プロパティ |
currentDomain:ApplicationDomain [読み取り専用] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0, Flash Player 9, Flash Lite 4 |
コードが実行されている現在のアプリケーションドメインを取得します。
実装
public static function get currentDomain():ApplicationDomaindomainMemory | プロパティ |
MIN_DOMAIN_MEMORY_LENGTH | プロパティ |
parentDomain | プロパティ |
parentDomain:ApplicationDomain [読み取り専用] | 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0, Flash Player 9, Flash Lite 4 |
このアプリケーションドメインの親ドメインを取得します。
実装
public function get parentDomain():ApplicationDomainApplicationDomain | () | コンストラクター |
public function ApplicationDomain(parentDomain:ApplicationDomain = null)| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0, Flash Player 9, Flash Lite 4 |
新しいアプリケーションドメインを作成します。
パラメーターparentDomain:ApplicationDomain (default = null) — 親ドメインが渡されない場合、このアプリケーションドメインはシステムドメインを親ドメインとします。
|
getDefinition | () | メソッド |
public function getDefinition(name:String):Object| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | AIR 1.0, Flash Player 9, Flash Lite 4 |
指定されたアプリケーションドメインから公開定義を取得します。定義には、クラス、名前空間または関数の定義があります。
パラメーター
name:String — 定義の名前です。
|
Object — 定義に関連付けられたオブジェクトです。
|
例外
ReferenceError — 指定された名前の公開定義は存在しません。
|
getQualifiedDefinitionNames | () | メソッド |
public function getQualifiedDefinitionNames():Vector.<String>| 言語バージョン: | ActionScript 3.0 |
| ランタイムバージョン: | Flash Player 11.3, AIR 3.3 |
指定されたアプリケーションドメインから公開定義のすべての完全修飾名を取得します。定義には、クラス、名前空間または関数の定義があります。このメソッドから返された名前を getDefinition() メソッドに渡して、実際の定義のオブジェクトを取得できます。
返される Vector は String 型です。それぞれの String の形式は次のとおりです。package.path::definitionName
definitionName がトップレベルのパッケージの場合は、package.path:: 部分が省略されます。
例えば、次のようなクラス定義があるとします。
package my.Example
{
public class SampleClass extends Sprite
{ }
}
このメソッドは、"my.Example::SampleClass" を返します。
戻り値Vector.<String> — 定義名の String を格納する並べ替えされていない Vector。定義がない場合は、空の Vector となります。<String> が返されます。
|
例外
SecurityError — 定義が属しているドメインに対するアクセス権が呼び出し側のコードにありません。
|
hasDefinition | () | メソッド |
注意:
- ClassLoader クラスによって SWF ファイルがロードされるので、ローカルセキュリティはファイルシステムレベルである必要があります。
- この例を実行するには、"ApplicationDomainExample.swf" ファイルと同じフォルダーに存在する "RuntimeClasses.swf" という 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));
}
}
ApplicationDomain.currentDomain を使用するように指示されました。今回は、新しい ApplicationDomain が作成されます。これにより、2 番目にロードされる任意の SWF の Greeter クラスのプロパティおよびメソッドが、最初の Greeter クラスのプロパティおよびメソッドと置き換わることはありません。これは、context.applicationDomain プロパティ(load メソッド)をプロパティを変更してテストできます。このメソッドは ClassLoader 内のものです。
注意:
- ClassLoader クラスによって SWF ファイルがロードされるので、ローカルセキュリティはファイルシステムレベルである必要があります。
- この例を実行するには、Greeter.swf と呼ばれる 2 つの SWF ファイルがそれぞれ "en" フォルダーおよび "es" フォルダーに存在している必要があります。
以下のコードを使用して、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));
}
}
Tue Jun 12 2018, 10:34 AM Z
継承されるパブリックプロパティを隠す
継承されるパブリックプロパティを表示