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.
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...