Using HTTP to connect to server-side scripts
641
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.
Create a button symbol, drag an instance on to the Stage, and give it an instance name of
submit_btn
.
7.
Select Frame 1 in the Timeline, and open the Actions panel (Window > 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();
emailResponse.onLoad = function(success:Boolean) {
if (success) {
debug_txt.text = this.result;
} else {
debug_txt.text = "error downloading content";
}
};
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");
};
This ActionScript creates a new LoadVars object instance, copies the values from the text
fields into the instance, and then sends the data to the server. The CFM file sends the e-
mail and returns a variable (
true
or
false
) to the SWF file called
result
, which appears
in the
debug_txt
text field.
9.
Save the document as
sendEmail.fla
, and then publish it by selecting File > Publish.
10.
Upload sendEmail.swf to the same directory that contains email.cfm (the ColdFusion file
you saved and uploaded in step 2).
11.
View and test the SWF file in a browser.
For more information, see the LoadVars entry in the
ActionScript 2.0 Language
Reference.
NO
T
E
Remember to change the URL www.yoursite.com to your own domain.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...