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

Display programming<br />

The LoaderInfo object can be accessed as a property of both the Loader object and the loaded display object. As soon<br />

as loading begins, the LoaderInfo object can be accessed through the cont<strong>en</strong>tLoaderInfo property of the Loader<br />

object. Once the display object has finished loading, the LoaderInfo object can also be accessed as a property of the<br />

loaded display object through the display object’s loaderInfo property. The loaderInfo property of the loaded<br />

display object refers to the same LoaderInfo object as the cont<strong>en</strong>tLoaderInfo property of the Loader object. In other<br />

words, a LoaderInfo object is shared betwe<strong>en</strong> a loaded object and the Loader object that loaded it (betwe<strong>en</strong> loader and<br />

loadee).<br />

In order to access properties of loaded cont<strong>en</strong>t, you will want to add an ev<strong>en</strong>t list<strong>en</strong>er to the LoaderInfo object, as in<br />

the following code:<br />

import flash.display.Loader;<br />

import flash.display.Sprite;<br />

import flash.ev<strong>en</strong>ts.Ev<strong>en</strong>t;<br />

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

var urlReq:URLRequest = new URLRequest("Circle.swf");<br />

ldr.load(urlReq);<br />

ldr.cont<strong>en</strong>tLoaderInfo.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, loaded);<br />

addChild(ldr);<br />

function loaded(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

var cont<strong>en</strong>t:Sprite = ev<strong>en</strong>t.target.cont<strong>en</strong>t;<br />

cont<strong>en</strong>t.scaleX = 2;<br />

}<br />

For more information, see “Handling ev<strong>en</strong>ts” on page 125.<br />

Specifying loading context<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> you load an external file into Flash Player or AIR through the load() or loadBytes() method of the Loader<br />

class, you can optionally specify a context parameter. This parameter is a LoaderContext object.<br />

The LoaderContext class includes three properties that let you define the context of how the loaded cont<strong>en</strong>t can be<br />

used:<br />

checkPolicyFile: Use this property only wh<strong>en</strong> loading an image file (not a SWF file). If you set this property to<br />

true, the Loader checks the origin server for a policy file (see “Website controls (policy files)” on page 1040). This<br />

is necessary only for cont<strong>en</strong>t originating from domains other than that of the SWF file containing the Loader object.<br />

If the server grants permission to the Loader domain, ActionScript from SWF files in the Loader domain can access<br />

data in the loaded image; in other words, you can use the BitmapData.draw() command to access data in the<br />

loaded image.<br />

Note that a SWF file from other domains than that of the Loader object can call Security.allowDomain() to<br />

permit a specific domain.<br />

securityDomain: Use this property only wh<strong>en</strong> loading a SWF file (not an image). Specify this for a SWF file from<br />

a domain other than that of the file containing the Loader object. Wh<strong>en</strong> you specify this option, Flash Player checks<br />

for the exist<strong>en</strong>ce of a policy file, and if one exists, SWF files from the domains permitted in the cross-policy file can<br />

cross-script the loaded SWF cont<strong>en</strong>t. You can specify flash.system.SecurityDomain.curr<strong>en</strong>tDomain as this<br />

parameter.<br />

Last updated 6/6/2012<br />

200

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

Saved successfully!

Ooh no, something went wrong!