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

Setting LocalConnection permissions<br />

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

The LocalConnection class lets you s<strong>en</strong>d messages betwe<strong>en</strong> one Flash Player or AIR application and another.<br />

LocalConnection objects can communicate only among Flash Player or AIR cont<strong>en</strong>t running on the same cli<strong>en</strong>t<br />

computer, but they can be running in differ<strong>en</strong>t applications—for example, a SWF file running in a browser, a SWF file<br />

running in a projector, and an AIR application can all communicate use the LocalConnection class.<br />

For every LocalConnection communication, there is a s<strong>en</strong>der and a list<strong>en</strong>er. By default, Flash Player allows<br />

LocalConnection communication betwe<strong>en</strong> code running in the same domain. For code running in differ<strong>en</strong>t<br />

sandboxes, the list<strong>en</strong>er must allow the s<strong>en</strong>der permission by using the LocalConnection.allowDomain() method.<br />

The string you pass as an argum<strong>en</strong>t to the LocalConnection.allowDomain() method can contain any of the<br />

following: exact domain names, IP addresses, and the * wildcard.<br />

The allowDomain() method has changed from the form it had in ActionScript 1.0 and 2.0. In those earlier versions,<br />

allowDomain() was a callback method that you implem<strong>en</strong>ted. In ActionScript 3.0, allowDomain() is a built-in<br />

method of the LocalConnection class that you call. With this change, allowDomain() works in much the same way as<br />

Security.allowDomain().<br />

A SWF file can use the domain property of the LocalConnection class to determine its domain.<br />

Controlling outbound URL access<br />

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

Outbound scripting and URL access (through the use of HTTP URLs, mailto: and so on) are achieved through use of<br />

the following APIs:<br />

The flash.system.fscommand() function<br />

The ExternalInterface.call() method<br />

The flash.net.navigateToURL() function<br />

For cont<strong>en</strong>t loaded from the local file system, calls to these methods are successful only if the code and the containing<br />

web page (if there is one) are in the local-trusted or AIR application security sandboxes. Calls to these methods fail if<br />

the cont<strong>en</strong>t is in the local-with-networking or local-with-filesystem sandbox.<br />

For cont<strong>en</strong>t that is not loaded locally, all of these APIs can communicate with the web page in which they are<br />

embedded, dep<strong>en</strong>ding on the value of the AllowScriptAccess parameter described below. The<br />

flash.net.navigateToURL() function has the additional ability to communicate with any op<strong>en</strong> browser window or<br />

frame, not just the page in which the SWF file is embedded. For more information on this functionality, see “Using the<br />

navigateToURL() function” on page 1062.<br />

The AllowScriptAccess parameter in the HTML code that loads a SWF file controls the ability to perform outbound<br />

URL access from within the SWF file. Set this parameter inside the PARAM or EMBED tag. If no value is set for<br />

AllowScriptAccess, the SWF file and the HTML page can communicate only if both are from the same domain.<br />

The AllowScriptAccess parameter can have one of three possible values: "always", "sameDomain", or "never".<br />

Wh<strong>en</strong> AllowScriptAccess is "always", the SWF file can communicate with the HTML page in which it is<br />

embedded ev<strong>en</strong> wh<strong>en</strong> the SWF file is from a differ<strong>en</strong>t domain than the HTML page.<br />

Last updated 6/6/2012<br />

1061

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

Saved successfully!

Ooh no, something went wrong!