Chapter 14: Networking And Communication; Working With External Data - Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual

Programming actionscript 3.0
Table of Contents

Advertisement

Working with external data

When you build large ActionScript applications, you often need to communicate with server-
side scripts, or load data from external XML or text files. This behavior has changed
significantly between ActionScript 2.0 and ActionScript 3.0. In earlier versions of
ActionScript, you could load remote text files using the LoadVars class and the
LoadVars.onData()
URLLoader and URLRequest classes. If the remote content is formatted as name-value pairs,
you use the URLVariables class to parse the server results.
You use the URLLoader and URLRequest classes to load the remote XML document. You can
then parse the XML document using the XML class's constructor, the XMLDocument class's
constructor, or the
XMLDocument.parseXML()
ActionScript code because the code for loading external files is the same whether you use
URLVariables or the XML classes.
Using the URLLoader and URLVariables classes
ActionScript 3.0 has replaced the LoadVars class with URLLoader and URLVariables classes.
The URLLoader class downloads data from a URL as text, binary data, or URL-encoded
variables. The URLLoader class is useful for downloading text files, XML, or other
information to use in dynamic, data-driven ActionScript applications. The URLLoader class
takes advantage of the ActionScript 3.0 advanced event handling model, which allows you to
listen for such events as
. The new event handling model is a significant improvement over the
securityError
ActionScript 2.0 support for the
event handlers because it allows you to handle errors and events more
LoadVars.onLoad
efficiently. For more information on handling events, see
Much like the XML and LoadVars classes in earlier versions of ActionScript, the data of the
URLLoader URL is not available until the download has completed. You can monitor the
progress of the download (bytes loaded and bytes total) by listening for the
flash.events.ProgressEvent.PROGRESS
quickly a
ProgressEvent.PROGRESS
successfully downloaded, the
loaded data is decoded from UTF-8 or UTF-16 encoding into a string.
If no value is set for
.
urlencoded
372
Networking and Communication
event handler. In ActionScript 3.0, you can load external files with the
,
complete
httpStatus
LoadVars.onData
event may not be dispatched. When a file has
flash.events.Event.COMPLETE
URLRequest.contentType
method. This allows you to simplify your
,
,
,
ioError
open
,
LoadVars.onHTTPStatus
Chapter 13, "Handling Events."
event to be dispatched, although if a file loads too
event will be dispatched. The
, values are sent as
, and
progress
, and
application/x-www-form-

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents