Example Name: SampleDatabaseMethods.fla
Language: ActionScript 1.0
Version: 1.0.0
Code:
#include "NetServices.as"
// Set up variables for the URL and service paths
var myURL = "http://localhost/flashservices/gateway";
var servicePath = "com.oreilly.frdg.SampleDatabaseMethods";
// Define the custom class SimpleResult
function UpdateResult() {
this.onResult = function(myResults){
results_txt.text = "Update employee successful";
//do some housekeeping after updating an employee
}
this.onStatus = errorHandler;
}
function AddResult() {
this.onResult = function(myResults){
results_txt.text = "Add employee successful";
//do some housekeeping after adding an employee
}
this.onStatus = errorHandler;
}
function DeleteResult() {
this.onResult = function(myResults){
results_txt.text = "Delete employee successful";
//do some housekeeping after deleting an employee
}
this.onStatus = errorHandler;
}
System.onStatus = errorHandler;
function errorHandler(myError) {
results_txt.text = myError.description;
}
// Connection hasn't been initialized; create connection and service objects
if (initialized == null) {
initialized = true;
NetServices.setDefaultGatewayURL(myURL);
var myConnection_conn = NetServices.createGatewayConnection();
var service = myConnection_conn.getService(servicePath);
}
// Set up the callback functions to handle mouseclicks
add_pb.setClickHandler("callAdd");
update_pb.setClickHandler("callUpdate");
delete_pb.setClickHandler("callDelete");
// Call the remote service when the user clicks the buttons.
function callAdd () {
service.addEmployee(new AddResult(), "");
}
function callUpdate () {
service.updateEmployee(new UpdateResult(), "");
}
function callDelete () {
service.deleteEmployee(new DeleteResult(), "");
}
Download code text
Download chapter example files