13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Working with application domains<br />

var appDomainB:ApplicationDomain = ApplicationDomain.curr<strong>en</strong>tDomain;<br />

var contextB:LoaderContext = new LoaderContext(false, appDomainB);<br />

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

loaderB.load(new URLRequest("module1.swf"), contextB);<br />

Usage C: Use the par<strong>en</strong>t’s class definitions by creating a new child domain of the curr<strong>en</strong>t domain. The application<br />

domain of module3.swf is a child of the curr<strong>en</strong>t domain, and the child uses the par<strong>en</strong>t's versions of all classes. One use<br />

of this technique might be a module of a multiple-scre<strong>en</strong> rich Internet application (RIA), loaded as a child of the main<br />

application, that uses the main application's types. If you can <strong>en</strong>sure that all classes are always updated to be backward<br />

compatible, and that the loading application is always newer than the things it loads, the childr<strong>en</strong> will use the par<strong>en</strong>t<br />

versions. Having a new application domain also allows you to unload all the class definitions for garbage collection, if<br />

you can <strong>en</strong>sure that you do not continue to have refer<strong>en</strong>ces to the child SWF.<br />

This technique lets loaded modules share the loader's singleton objects and static class members.<br />

The following code creates a new child domain of the curr<strong>en</strong>t domain, and starts loading a SWF using that application<br />

domain:<br />

var appDomainC:ApplicationDomain = new ApplicationDomain(ApplicationDomain.curr<strong>en</strong>tDomain);<br />

var contextC:LoaderContext = new LoaderContext(false, appDomainC);<br />

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

loaderC.load(new URLRequest("module3.swf"), contextC);<br />

Last updated 6/6/2012<br />

150

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

Saved successfully!

Ooh no, something went wrong!