Quantumwave Interactive Inc.
  Interactive media development . Programming . Design . Consulting

Simple demo of Server-Side ActionScript (SSAS) and Flash Remoting

This simple demo has a function to list objects on the server-side. It creates a service called listObject with methods listObj(), and listCF() - which lists the properties and methods of the CF object.

This is the server-side ActionScript file - listObject.asr (placed inside wwwroot/flashservices/):
function countProp(obj) {
   var n = 0;
   for (var p in obj) n++;
   return n;
};

//---------------------------------------------------------------------------

function listObj(obj, doSort) {
   listObj.lev++;
   var a = [];
   var pCount = 0;

   for (var p in obj) {
      pCount++;
      var pVal = obj[p];
      var pType = typeof pVal;
      if (pType == "function") {
         a.push(pVal);
      } else if (pType == "object") {
         a.push("object "+ p +" = "+ pVal +"\n");
         // Recursively list internal objects (disabled 'class' because of stack overflow)
         if ((pVal != null) && (p != "class") && (countProp(pVal) > 0)) listObj(pVal);
      } else {
         a.push(pType +" "+ p +":"+ pVal +"\n");
      }
   }

   if (doSort == true) a.sort();

   var txt = "";
   for (var i=0; i<a.length; i++) {
      txt += a[i] + "\n";
   }

   if (a.length > 0) {
      txt += ("@" + listObj.lev +" #"+ pCount +
         "\n-----------------------------------------------------------------------------\n");
   }

   listObj.lev--;
   return txt;
};

listObj.lev = 0;

//---------------------------------------------------------------------------

// list and sort the CF object properties and methods
function listCF() {
   return listObj(CF, true);
};

Here is the client-side ActionScript in a Flash MX movie:
#include "NetServices.as"

// function to encapsulate the code to get a service
_global.getNetService = function(baseURL, URL, callback) {
   NetServices.setDefaultGatewayUrl(baseURL);
   return NetServices.createGatewayConnection().getService(URL, callback);
};

// callback object to display the result or error
var callback = {
   onResult: function(r) { trace(r); },
   onStatus: function(s) { trace("onStatus: "+ s.description); }
}

// set up the URL and service path (my server setup uses the standard HTTP port 80);
// you may need to use a different port such as http://localhost:8500/...
var baseURL = "http://localhost/flashservices/gateway";
var servicePath = "flashservices.listObject";

var srv = getNetService(baseURL, servicePath, callback);

// invoke the listCF method
srv.listCF();


Click here to see the trace output, or go see other Flash articles.

Download source file: listCFObject.zip (Flash MX)

Last updated on: May 11, 2002 - Copyright © 2002 Dave Yang / Quantumwave Interactive Inc.

home | about | news | flash | director | shockwave | download | dave | résumé | contact

Copyright © 1995-2009 Quantumwave Interactive Inc.