User Guide

Sending and loading variables to and from a remote source 279
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.
Note: You must have ColdFusion installed on your web server for this example.
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 IsDefined("Form")>
<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.
4.
Create four input text fields on the Stage, and give them the following instance names:
emailFrom_txt, emailTo_txt, emailSubject_txt, and emailBody_txt.
5.
Create a dynamic text field on the Stage with the instance name debug_txt.
6.
Drag a PushButton component instance to the Stage, and give it the instance name
submit_btn.
7.
Select Frame 1 in the Timeline, and open the Actions panel (Window > Development Panels >
Actions) if it isn’t already open.
8.
Enter the following code in the Actions panel:
this.submit_btn.onRelease = function() {
var emailResponse:LoadVars = new LoadVars();
var email:LoadVars = new LoadVars();
email.emailFrom = emailFrom_txt.text;
email.emailTo = emailTo_txt.text;
email.emailSubject = emailSubject_txt.text;
email.emailBody = emailBody_txt.text;
email.sendAndLoad("http://www.yoursite.com/email.cfm", emailResponse,
"POST");
emailResponse.onLoad = function() {
debug_txt.text = this.result;
};
};