O'Reilly logo

ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, Keith Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending XML

Problem

You want to send XML data to a server-side script.

Solution

Create a URLRequest instance containing the XML data to send. Use flash.net.sendToURL() to send the data and ignore the server response, use flash.net.navigateToURL() to send the data and open the server response in a specific browser window, or use URLLoader.load() to both send the data and download the response into the .swf file.

Discussion

XML is normally used to transfer data to and from applications, and in this case, Flash movies. Therefore, it is quite unusual that you would want to create XML objects in your Flash movies for use within Flash alone. Instead, you generally load XML data from another source, create XML data in Flash for the purpose of sending to another application, or both.

This recipe examines sending XML data from Flash to another application, and there are lots of reasons to do this. For example, in a Flash game you might want to use XML to send the user’s name and score to the server. At other times, you might want to send XML packets to a server-side script to invoke server-side functionality. This is a process that is sometimes called a remote procedure call (RPC), and it can use XML to send the function invocation information (function name, parameters, etc.) to the server. There is a formal specification for using XML in this manner called XML-RPC (see http://www.xmlrpc.com). So, as you can see, the possibilities for sending XML to the server are quite diverse.

As discussed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required