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

HTTP communications<br />

Wh<strong>en</strong> your application runs in a browser, you can only use web services in the same Internet domain as the calling<br />

SWF unless the server hosting the web service also hosts a cross-domain policy file that permits access from other<br />

domains. A technique that is oft<strong>en</strong> used wh<strong>en</strong> a cross-domain policy file is not available is to proxy the requests<br />

through your own server. Adobe Blaze DS and Adobe LiveCycle support web service proxying.<br />

In AIR applications, a cross-domain policy file is not required wh<strong>en</strong> the web service call originates from the application<br />

security sandbox. AIR application cont<strong>en</strong>t is never served from a remote domain, so it cannot participate in the types<br />

of attacks that cross-domain policies prev<strong>en</strong>t. In HTML-based AIR applications, cont<strong>en</strong>t in the application security<br />

sandbox can make cross-domain XMLHttpRequests. You can allow cont<strong>en</strong>t in other security sandboxes to make crossdomain<br />

XMLHttpRequests as long as that cont<strong>en</strong>t is loaded into an iframe.<br />

More Help topics<br />

“Website controls (policy files)” on page 1040<br />

Adobe BlazeDS<br />

Adobe LiveCycle ES2<br />

REST architecture<br />

XML-RPC<br />

SOAP protocol<br />

REST-style web service requests<br />

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

REST-style web services use HTTP method verbs to designate the basic action and URL variables to specify the action<br />

details. For example, a request to get data for an item could use the GET verb and URL variables to specify a method<br />

name and item ID. The resulting URL string might look like:<br />

http://service.example.com/?method=getItem&id=d3452<br />

To access a REST-style web service with ActionScript, you can use the URLRequest, URLVariables, and URLLoader<br />

classes. In JavaScript code within an AIR application, you can also use an XMLHttpRequest.<br />

Programming a REST-style web service call in ActionScript, typically involves the following steps:<br />

1 Create a URLRequest object.<br />

2 Set the service URL and HTTP method verb on the request object.<br />

3 Create a URLVariables object.<br />

4 Set the service call parameters as dynamic properties of the variables object.<br />

5 Assign the variables object to the data property of the request object.<br />

6 S<strong>en</strong>d the call to the service with a URLLoader object.<br />

7 Handle the complete ev<strong>en</strong>t dispatched by the URLLoader that indicates that the service call is complete. It is also<br />

wise to list<strong>en</strong> for the various error ev<strong>en</strong>ts that can be dispatched by a URLLoader object.<br />

For example, consider a web service that exposes a test method that echoes the call parameters back to the requestor.<br />

The following ActionScript code could be used to call the service:<br />

Last updated 6/6/2012<br />

820

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

Saved successfully!

Ooh no, something went wrong!