ApplicationDomain类应用实例

来源:互联网 发布:js修改div style 编辑:程序博客网 时间:2024/05/21 08:02

ApplicationDomain 类是分散的类定义组的一个容器。

在通过 Loader 类加载外部 SWF 文件时会使用应用程序域。 加载的 SWF 文件中的所有 ActionScript 3.0 定义都存储在由 LoaderContext 对象的applicationDomain 属性指定的应用程序域中,此对象是您为 Loader 对象的load()loadBytes() 方法传递的 context 参数。

package
{
 import flash.display.Loader;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.net.URLRequest;
 import flash.sampler.NewObjectSample;
 import flash.system.ApplicationDomain;
 import flash.system.LoaderContext;
 import flash.text.TextField;
 
 public class ApplicationDomainTest extends Sprite
 { 
  private var loader:Loader;
  private var mytext:TextField = new TextField();
  public function ApplicationDomainTest()
  { 
   loader = new Loader();
   init();
  }
  
  
  private function init():void
  { 
   addChild(mytext);
   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
   loader.load(new URLRequest("RuntimeClasses.swf"),new LoaderContext       (false,ApplicationDomain.currentDomain));
  }
  
  private function completeHandler(event:Event):void
  {
   var myClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("RuntimeClasses") as Class;
   var greeter:Object = new myClass();
   mytext.text = greeter.greet();
  }
 }
}