640 Working with External Data
■ You don’t need to create container movie clips for holding data or clutter existing movie
clips with variables specific to client/server communication.
■ The class interface is similar to that of the XML object, which provides some consistency
in ActionScript. It uses the methods
load(), send(), and sendAndLoad() to initiate
communication with a server. The main difference between the LoadVars and XML
classes is that the LoadVars data is a property of the LoadVars object rather than of an
XML Document Object Model (DOM) tree stored in the XML object.
■ The class interface is more straightforward—with methods named load, send,
sendAndLoad—than the older loadVariables interface.
■ You can get additional information about the communication, using the getBytesLoaded
and
getBytesTotal methods.
■ You can get progress information about the download of your data (although you can’t
access the data until it is fully downloaded).
■ The callback interface is through ActionScript methods (onLoad) instead of the obsolete,
deprecated
onClipEvent (data) approach required for loadVariables.
■ There are error notifications.
■ You can add custom HTTP request headers.
You must create a LoadVars object to call its methods. This object is a container to hold the
loaded data.
The following procedure shows how to use ColdFusion and the LoadVars class to send an e-
mail from a SWF file.
To load data with the LoadVars object:
1. Create a CFM file in Macromedia Dreamweaver or in your favorite text editor. Add the
following text to the file:
<cfif StructKeyExists(Form, "emailTo")>
<cfmail to="#Form.emailTo#" from="#Form.emailFrom#"
subject="#Form.emailSubject#">#Form.emailBody#</cfmail>
&result=true
<cfelse>
&result=false
</cfif>
2.
Save the file as email.cfm, and upload it to your website.
3. In Flash, create a new document.
NOTE
You must have ColdFusion installed on your web server for this example.