Example Number 5.10

Example Name: Customers.fla

Language: ActionScript 1.0

Version: 1.0.0

Code:

#include "NetServices.as"

NetServices.setDefaultGatewayURL("http://localhost/flashservices/gateway");
var my_conn = NetServices.createGatewayConnection();
var customerService = my_conn.getService("com.oreilly.frdg.Customers",this);
customerService.getCustomers();

// Declares the IncomingDataHandler object's constructor.
function IncomingDataHandler(rs) {
  this.rs = rs;
}

// Get the rows that the server sent back immediately. Should be
// equal to the Flash.Pagesize variable set on the server.
IncomingDataHandler.prototype.getData = function() {
  for (var i = 0; i < this.rs.getNumberAvailable(); ++i) {
    trace(this.rs.getItemAt(i)["ContactName"]);
  }
}

// This is the function that will automatically be
//  called as data is returned from the server.
IncomingDataHandler.prototype.modelChanged = function (info) {
  if (info.event == "updateRows") {
    for (var i = info.firstRow; i <= info.lastRow; ++i) {
      trace(this.rs.getItemAt(i)["ContactName"]);
    }
  }
}

function onResult(result) {
  // Fetch all records, but only 10 at-a-time.
  result.setDeliveryMode("fetchall",10);
  var dataHandler = new IncomingDataHandler(result);
  result.addView(dataHandler);
  dataHandler.getData();
}

function onStatus(error) {
  trace("error: " + error.description);
}

Download code text

Download chapter example files