Using the 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 } } }
Using the ApplicationDomain class Other things to keep in mind when you work with application domains include
the following:
- All code in a SWF file is defined to exist in an application domain.
The current domain is where your main application runs.
The system domain contains all application domains, including the current
domain, which means that it contains all Flash Player classes. - All application domains, except the system domain, have an associated parent
domain. The parent domain for your main application's application domain is
the system domain. Loaded classes are defined only when their parent doesn't
already define them. You cannot override a loaded class definition with
a newer definition.
1 comment:
viagra shelf life low cost viagra viagra benefits viagra facts viagra larger forever viagra blood pressure viagra online uk natural herbs used as viagra bad side effects of viagra buying viagra in uk cheap viagra canada cheap viagra canada marijuana and viagra buy cheap viagra soft
Post a Comment