Invoking a Server Function from Macromedia Flash

Listing E.14 will call the method sayHelloServer, which was created in the SSAS Client object when the client connected.

Listing E.14 Flash ActionScript for Invoking a Server Function
nc = new NetConnection();
nc.onStatus = function() {
     nc.call("sayHelloServer", new server_ret());
};
nc.connect("rtmp://localhost/myApplication/myInstance");

// handle the method results returned from the server.
server_ret = function () {
      this.onResult = function(value_ret) {
            trace("Message From the Server: "+value_ret);
      };

      this.onStatus = function() {
            trace("Method Failed");
      };

};

There are two ways to create a client function on the server. Option A (in Listing E.15) creates the function on the unique client instance when it connects.

Listing E.15 Server-Side ActionScript (Option A) for Invoking a Server Function
application.onConnect = function(clientObject) {
      application.acceptConnection(clientObject);

      // Define a function for the Client to Call  - send him an object
      clientObject.sayHelloServer = function() {
            // Trace in the App Inspector
            trace("The client says How Ya Doin, Bucko.. Got Somthin' for ya!");

            // return a string to the Flash Player
            return ("FlashCom Server Rocks!");
      };
};

Shown in Listing E.16, Option B will create a prototype function that all clients can access.

Listing E.16 Server-Side ActionScript (Option B) for Invoking a Server Function
clientObject.prototype.sayHelloServer = function() {
      // Trace in the App Inspector
      trace("The client says How Ya Doin, Bucko.. Got Somthin' for ya!");
      // return a string to the Flash Player
      return ("FlashCom Server Rocks!");
};


    Part I: 10 Quick Steps for Getting Started
     
    ASPTreeView.com
     
    Evaluation has ГЦМµёЕexpired.
    Info...