29.04.2013 Views

ACTIONSCRIPT 3.0

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> <strong>3.0</strong> DEVELOPER’S GUIDE<br />

Working with application domains<br />

Stage<br />

Application<br />

Loader<br />

A. Usage A B. Usage B C. Usage C<br />

application1.swf<br />

Loader<br />

Loader<br />

Loader<br />

Module<br />

Security domain: domain1.com<br />

Application domain 1<br />

Module<br />

Application domain 2<br />

mx.core.Application<br />

application2.swf<br />

mx.core.Application<br />

module1.swf<br />

Application domain 3<br />

module3.swf<br />

Module<br />

The main application file is application1.swf. It contains Loader objects that load content from other SWF files. In this<br />

scenario, the current domain is Application domain 1. Usage A, usage B, and usage C illustrate different techniques<br />

for setting the appropriate application domain for each SWF file in an application.<br />

Usage A Partition the child SWF file by creating a child of the system domain. In the diagram, Application domain 2<br />

is created as a child of the system domain.The application2.swf file is loaded in Application domain 2, and its class<br />

definitions are thus partitioned from the classes defined in application1.swf.<br />

One use of this technique is to have an old application dynamically loading a newer version of the same application<br />

without conflict. There is no conflict because although the same class names are used, they are partitioned into<br />

different application domains.<br />

The following code creates an application domain that is a child of the system domain, and starts loading a SWF using<br />

that application domain:<br />

var appDomainA:ApplicationDomain = new ApplicationDomain();<br />

var contextA:LoaderContext = new LoaderContext(false, appDomainA);<br />

var loaderA:Loader = new Loader();<br />

loaderA.load(new URLRequest("application2.swf"), contextA);<br />

Usage B: Add new class definitions to current class definitions. The application domain of module1.swf is set to the<br />

current domain (Application domain 1). This lets you add to the application’s current set of class definitions with new<br />

class definitions. This could be used for a run-time shared library of the main application. The loaded SWF is treated<br />

as a remote shared library (RSL). Use this technique to load RSLs by a preloader before the application starts.<br />

The following code loads a SWF, setting its application domain to the current domain:<br />

Last updated 4/22/2013<br />

B<br />

C<br />

A<br />

149

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!