EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 641

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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.
NOTE
Remember to change the URL www.yoursite.com to your own domain.

Table of Contents

Related product manuals