Example Name: SendEmail.fla
Language: ActionScript 1.0
Version: 1.0.0
Code:
#include "NetServices.as"
var my_conn; // connection object
var emailService; // service object
var myURL = "http://localhost/flashservices/gateway";
// Responder for general service methods
function Responder() {
this.onResult = function(myResults) {
if(myResults == "") myResults = "Email sent!";
status_mb._visible = true;
status_mb.setMessage(myResults);
}
this.onStatus = function(theError) {
status_mb._visible = true;
status_mb.setMessage(theError.description);
System.onStatus = this.onStatus;
}
}
// Close the message box when OK is clicked
status_mb.setCloseHandler("closeBox");
function closeBox() {
status_mb.visible = false;
}
// Initialize Flash Remoting
function init() {
initialized = true;
NetServices.setDefaultGatewayUrl(myURL);
my_conn = NetServices.createGatewayConnection();
emailService = my_conn.getService("com.oreilly.frdg.cfPages");
}
init();
// Send the email when the send_pb button is clicked
send_pb.setClickHandler("send");
function send() {
var args = new Object();
args.toAddress = to_txt.text;
args.fromAddress = from_txt.text;
args.subject = subject_txt.text;
args.body = body_txt.text;
// Call the service, using the responder in the first argument
emailService.sendEmail(new Responder(), args);
}
Download code text
Download chapter example files