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

Security<br />

In any cross-domain situation, it is important to be clear about the two parties involved. For the purposes of this<br />

discussion, the side that is performing the cross-scripting is called the accessing party (usually the accessing SWF), and<br />

the other side is called the party being accessed (usually the SWF being accessed). Wh<strong>en</strong> siteA.swf scripts siteB.swf,<br />

siteA.swf is the accessing party, and siteB.swf is the party being accessed, as the following illustration shows:<br />

SWF<br />

siteA.com / swfA.swf<br />

var url:String = "http://siteB.com/swfB.swf";<br />

var req:URLRequest = new URLRequest(url);<br />

myLoader.load(req);<br />

myLoader.cont<strong>en</strong>t.eggCount = 3;<br />

myLoader.cont<strong>en</strong>t.DisplayEggs();<br />

cross-script<br />

3 2 permission<br />

Cross-domain permissions that are established with the Security.allowDomain() method are asymmetrical. In the<br />

previous example, siteA.swf can script siteB.swf, but siteB.swf cannot script siteA.swf, because siteA.swf has not called<br />

the Security.allowDomain() method to give SWF files at siteB.com permission to script it. You can set up<br />

symmetrical permissions by having both SWF files call the Security.allowDomain() method.<br />

In addition to protecting SWF files from cross-domain scripting originated by other SWF files, Flash Player protects<br />

SWF files from cross-domain scripting originated by HTML files. HTML-to-SWF scripting can occur with callbacks<br />

established through the ExternalInterface.addCallback() method. Wh<strong>en</strong> HTML-to-SWF scripting crosses<br />

domains, the SWF file being accessed must call the Security.allowDomain() method, just as wh<strong>en</strong> the accessing<br />

party is a SWF file, or the operation will fail. For more information, see “Author (developer) controls” on page 1043.<br />

Also, Flash Player provides security controls for SWF-to-HTML scripting. For more information, see “Controlling<br />

outbound URL access” on page 1061.<br />

Stage security<br />

Security.allowDomain("siteA.com");<br />

var eggCount:Number;<br />

function DisplayEggs() { ... };<br />

siteB.com / swfB.swf<br />

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

Some properties and methods of the Stage object are available to any sprite or movie clip on the display list.<br />

1<br />

However, the Stage object is said to have an owner: the first SWF file loaded. By default, the following properties and<br />

methods of the Stage object are available only to SWF files in the same security sandbox as the Stage owner:<br />

load<br />

SWF<br />

Last updated 6/6/2012<br />

1052

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

Saved successfully!

Ooh no, something went wrong!