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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

About the HTML <strong>en</strong>vironm<strong>en</strong>t<br />

To allow cont<strong>en</strong>t in a non-application sandbox to safely use AIR features, you can set up a par<strong>en</strong>t sandbox bridge. To<br />

allow application cont<strong>en</strong>t to safely call methods and access properties of cont<strong>en</strong>t in other sandboxes, you can set up a<br />

child sandbox bridge. Safety here means that remote cont<strong>en</strong>t cannot accid<strong>en</strong>tally get refer<strong>en</strong>ces to objects, properties,<br />

or methods that are not explicitly exposed. Only simple data types, functions, and anonymous objects can be passed<br />

across the bridge. However, you must still avoid explicitly exposing pot<strong>en</strong>tially dangerous functions. If, for example,<br />

you exposed an interface that allowed remote cont<strong>en</strong>t to read and write files anywhere on a user’s system, th<strong>en</strong> you<br />

might be giving remote cont<strong>en</strong>t the means to do considerable harm to your users.<br />

JavaScript eval() function<br />

Adobe AIR 1.0 and later<br />

Use of the eval() function is restricted within the application sandbox once a page has finished loading. Some uses<br />

are permitted so that JSON-formatted data can be safely parsed, but any evaluation that results in executable<br />

statem<strong>en</strong>ts results in an error. “Code restrictions for cont<strong>en</strong>t in differ<strong>en</strong>t sandboxes” on page 1071 describes the<br />

allowed uses of the eval() function.<br />

Function constructors<br />

Adobe AIR 1.0 and later<br />

In the application sandbox, function constructors can be used before a page has finished loading. After all page load<br />

ev<strong>en</strong>t handlers have finished, new functions cannot be created.<br />

Loading external scripts<br />

Adobe AIR 1.0 and later<br />

HTML pages in the application sandbox cannot use the script tag to load JavaScript files from outside of the<br />

application directory. For a page in your application to load a script from outside the application directory, the page<br />

must be mapped to a non-application sandbox.<br />

The XMLHttpRequest object<br />

Adobe AIR 1.0 and later<br />

AIR provides an XMLHttpRequest (XHR) object that applications can use to make data requests. The following<br />

example illustrates a simple data request:<br />

xmlhttp = new XMLHttpRequest();<br />

xmlhttp.op<strong>en</strong>("GET", "http:/www.example.com/file.data", true);<br />

xmlhttp.onreadystatechange = function() {<br />

if (xmlhttp.readyState == 4) {<br />

//do something with data...<br />

}<br />

}<br />

xmlhttp.s<strong>en</strong>d(null);<br />

In contrast to a browser, AIR allows cont<strong>en</strong>t running in the application sandbox to request data from any domain. The<br />

result of an XHR that contains a JSON string can be evaluated into data objects unless the result also contains<br />

executable code. If executable statem<strong>en</strong>ts are pres<strong>en</strong>t in the XHR result, an error is thrown and the evaluation attempt<br />

fails.<br />

To prev<strong>en</strong>t accid<strong>en</strong>tal injection of code from remote sources, synchronous XHRs return an empty result if made before<br />

a page has finished loading. Asynchronous XHRs will always return after a page has loaded.<br />

Last updated 6/6/2012<br />

964

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

Saved successfully!

Ooh no, something went wrong!