User Guide

Sending and loading variables to and from a remote source 71
In the following example, <portfolio> is the parent node; it has no attributes and contains the
child node
<holding>, which has the attributes symbol, qty, price, and value:
<portfolio>
<holding symbol="rich"
qty="75"
price="245.50"
value="18412.50" />
</portfolio>
For more information on XML, see www.w3.org/XML.
Using the XML class
The methods of the ActionScript XML class (for example,
appendChild(), removeNode(), and
insertBefore()) let you structure XML data in Flash to send to a server and manipulate and
interpret downloaded XML data.
The following XML class methods send and load XML data to a server by using the HTTP
POST method:
The load() method downloads XML from a URL and places it in an ActionScript
XML object.
The send()method encodes the XML object into an XML document and sends it to a
specified URL using the
POST method. If specified, a browser window displays returned data.
The sendAndLoad() method sends an XML object to a URL. Any returned information is
placed in an ActionScript XML object.
For more information, see the XML class entry and Developing Flex Applications.
Using the XMLSocket class
ActionScript provides a built-in XMLSocket class, which lets you open a continuous connection
with a server. A socket connection lets the server publish, or push, information to the client as
soon as that information is available. Without a continuous connection, the server must wait for
an HTTP request. This open connection removes latency issues and is commonly used for real-
time applications such as chats. The data is sent over the socket connection as one string and
should be formatted as XML. You can use the XML class to structure the data.
To create a socket connection, you must create a server-side application to wait for the socket
connection request and send a response to the SWF file. This type of server-side application can
be written in a programming language such as Java.
Note: The XMLSocket class cannot tunnel through firewalls automatically because, unlike RTMP
protocol, XMLSocket has no HTTP tunneling capability. If you need to use HTTP tunneling, consider
using Flash Remoting or Flash Communication Server (which supports RTMP) instead.
You can use the connect() and send() methods of the XMLSocket class to transfer XML to and
from a server over a socket connection. The
connect() method establishes a socket connection
with a web server port. The
send() method passes an XML object to the server specified in the
socket connection.