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

var variables:URLVariables = new URLVariables("name=Franklin");<br />

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

request.url = "http://www.[yourdomain].com/greeting.cfm";<br />

request.method = URLRequestMethod.POST;<br />

request.data = variables;<br />

var loader:URLLoader = new URLLoader();<br />

loader.dataFormat = URLLoaderDataFormat.VARIABLES;<br />

loader.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, completeHandler);<br />

try<br />

{<br />

loader.load(request);<br />

}<br />

catch (error:Error)<br />

{<br />

trace("Unable to load URL");<br />

}<br />

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

{<br />

trace(ev<strong>en</strong>t.target.data.welcomeMessage);<br />

}<br />

The following code contains the cont<strong>en</strong>ts of the Adobe ColdFusion® greeting.cfm docum<strong>en</strong>t used in the previous<br />

example:<br />

<br />

<br />

<br />

welcomeMessage=#UrlEncodedFormat("Welcome, " & Form.name)#<br />

<br />

Web service requests<br />

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

There are a variety of HTTP-based web services. The main types include:<br />

REST<br />

XML-RPC<br />

SOAP<br />

To use a web service in ActionScript 3, you create a URLRequest object, construct the web service call using either URL<br />

variables or an XML docum<strong>en</strong>t, and s<strong>en</strong>d the call to the service using a URLLoader object. The Flex framework<br />

contains several classes that make it easier to use web services—especially useful wh<strong>en</strong> accessing complex SOAP<br />

services. Starting with Flash Professional CS3, you can use the Flex classes in applications developed with Flash<br />

Professional as well as in applications developed in Flash Builder.<br />

In HTML-based AIR applications, you can use either the URLRequest and URLLoader classes or the JavaScript<br />

XMLHttpRequest class. If desired, you can also create a SWF library that exposes the web service compon<strong>en</strong>ts of the<br />

Flex framework to your JavaScript code.<br />

Last updated 6/6/2012<br />

819

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

Saved successfully!

Ooh no, something went wrong!