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 />

Display programming<br />

applicationDomain: Use this property only when loading a SWF file written in ActionScript <strong>3.0</strong> (not an image or<br />

a SWF file written in ActionScript 1.0 or 2.0). When loading the file, you can specify that the file be included in the<br />

same application domain as that of the Loader object, by setting the applicationDomain parameter to<br />

flash.system.ApplicationDomain.currentDomain. By putting the loaded SWF file in the same application<br />

domain, you can access its classes directly. This can be useful if you are loading a SWF file that contains embedded<br />

media, which you can access via their associated class names. For more information, see “Working with application<br />

domains” on page 147.<br />

Here’s an example of checking for a policy file when loading a bitmap from another domain:<br />

var context:LoaderContext = new LoaderContext();<br />

context.checkPolicyFile = true;<br />

var urlReq:URLRequest = new URLRequest("http://www.[your_domain_here].com/photo11.jpg");<br />

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

ldr.load(urlReq, context);<br />

Here’s an example of checking for a policy file when loading a SWF from another domain, in order to place the file in<br />

the same security sandbox as the Loader object. Additionally, the code adds the classes in the loaded SWF file to the<br />

same application domain as that of the Loader object:<br />

var context:LoaderContext = new LoaderContext();<br />

context.securityDomain = SecurityDomain.currentDomain;<br />

context.applicationDomain = ApplicationDomain.currentDomain;<br />

var urlReq:URLRequest = new URLRequest("http://www.[your_domain_here].com/library.swf");<br />

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

ldr.load(urlReq, context);<br />

For more information, see the LoaderContext class in the ActionScript <strong>3.0</strong> Reference for the Adobe Flash Platform.<br />

Loading SWF files in AIR for iOS<br />

Adobe AIR 3.6 and later, iOS only<br />

On iOS devices, there are restrictions on loading and compiling code at runtime. Because of these restrictions, there<br />

are some necessary differences in the task of loading external SWF files into your application:<br />

All SWF files that contain ActionScript code must be included in the application package. No SWF containing code<br />

can be loaded from an external source such as over a network. As part of packaging the application, all ActionScript<br />

code in all SWF files in the application package is compiled to native code for iOS devices.<br />

You can’t load, unload, and then re-load a SWF file. If you attempt to do this, an error occurs.<br />

The behavior of loading into memory and then unloading it is the same as with desktop platforms. If you load a<br />

SWF file then unload it, all visual assets contained in the SWF are unloaded from memory. However, any class<br />

references to an ActionScript class in the loaded SWF remain in memory and can be accessed in ActionScript code.<br />

All loaded SWF files must be loaded in the same application domain as the main SWF file. This is not the default<br />

behavior, so for each SWF you load you must create a LoaderContext object specifying the main application<br />

domain, and pass that LoaderContext object to the Loader.load() method call. If you attempt to load a SWF in an<br />

application domain other than the main SWF application domain, an error occurs. This is true even if the loaded<br />

SWF only contains visual assets and no ActionScript code.<br />

The following example shows the code to use to load a SWF from the application package into the main SWF’s<br />

application domain:<br />

Last updated 4/22/2013<br />

201

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

Saved successfully!

Ooh no, something went wrong!