User Guide

436 Client System Environment
ApplicationDomain class
The purpose of the ApplicationDomain class is to store a table of ActionScript 3.0 definitions.
All code in a SWF file is defined to exist in an application domain. You use application
domains to partition classes that are in the same security domain. This allows multiple
definitions of the same class to exist and also lets children reuse parent definitions.
You can use application domains when loading an external SWF file written in ActionScript
3.0 using the Loader class API. (Note that you cannot use application domains when loading
an image or SWF file written in ActionScript 1.0 or ActionScript 2.0.) All ActionScript 3.0
definitions contained in the loaded class are stored in the application domain. When loading
the SWF file, you can specify that the file be included in the same application domain as that
of the Loader object, by setting the
applicationDomain parameter of the LoaderContext
object to
ApplicationDomain.currentDomain. By putting the loaded SWF file in the same
application domain, you can access its classes directly. This can be useful if you are loading a
SWF file that contains embedded media, which you can access via their associated class
names, or if you want to access the loaded SWF file’s methods, as shown in the following
example:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class ApplicationDomainExample extends Sprite
{
private var ldr:Loader;
public function ApplicationDomainExample()
{
ldr = new Loader();
var req:URLRequest = new URLRequest("Greeter.swf");
var ldrContext:LoaderContext = new LoaderContext(false,
ApplicationDomain.currentDomain);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,
completeHandler);
ldr.load(req, ldrContext);
}
private function completeHandler(event:Event):void
{
ApplicationDomain.currentDomain.getDefinition("Greeter");
var myGreeter:Greeter = Greeter(event.target.content);
var message:String = myGreeter.welcome("Tommy");
trace(message); // Hello, Tommy