Skip to main content
July 10, 2009
Question

Issues Calling Client Methods from Server (FMS 3.5)

  • July 10, 2009
  • 1 reply
  • 1258 views

Hi all,

  I'm a bit puzzled here.  I've looked online for a bunch of examples/samples, but, none of them seem to work or give me a straight answer.  Here's my setup/situation:

- Flash Media Server 3.5 (using ActionScript 3 for server-side code)

- Flex application (built in Flex Builder 3, using ActionScript 3)

Now, I'm trying to get the server-side ASC code to call something from a connected client.  It doesn't seem to work (thought everything else works beautifully).  I've tried stuff like the following in the server side:

- In the application.onConnect function, I've tried this:

...

currentClient.requestChat = function (reqID, destID)
{
  trace("Requesting chat...");
  currentClient.call("requestWaiting", new reqHandler(), reqID, destID);
};

...

(Where reqHandler is just some handler that I know gets called).

- I've also tried the following code outside the onConnect function:

Client.prototype.requestChat = function (reqID, destID)
{
  trace("Requesting chat...");
  this.call("requestWaiting", new reqHandler(), reqID, destID);
}

Both seem to fire appropriately (when triggered from another client).  However, the "requestWaiting" method call to the clients doesn't seem to work at all.  I've tried some AS 2 examples on the client side, like:

nc = new NetConnection();
  nc.client = new Object();

  // function for handling queueing of requests for this station
  nc.client.requestWaiting = function (reqID:String, destID:String):void {   
    trace("HELLO");
    // check to make sure this is the right location, and if so, queue it
    if (destID == "WhateverTheIDIs") {
    chatQueue.push(reqID);
    btnChatWaiting.visible = true;
    } // if     
  }

...but that doesn't seem to fire at all.  I know the Flex has "sealed" the NetConnection class itself, so I can't just "extend" it as I do the "client" property.

I've als tried some more AS 3-oriented stuff, like trying to make the "client" property reference a separate class that handles callbacks, but that doesn't work easily for me as I need access to properties in the class that contains the NetConnection.

Any help/tips would be GREATLY appreciated.  I'm still fairly new to Flash/Flex, but I'm loving Flash Media Server.

Thanks in advance!

Cheers,

Duncan

    This topic has been closed for replies.

    1 reply

    July 11, 2009

    Hi Duncan,

    Following below at the end are code snippets from a working Flex/AS3/FMIS 3.5 application for  a call from the FMIS SSAS to a method on the client (written in Flex/AS3).

    Also, I highly recommend that you download the "Flash Media Interactive  Server Feature Explorer".  It is an AIR app with full Flex/AS3 source code  (viewable inside the app), plus full FMIS SSAS .asc files for several demo  apps.  You download it here:
    http://www.adobe.com/devnet/flashmediaserver/articles/fmis_feature_explorer.html

    The Flash Media Interactive Server Feature Explorer includes 4 Flex/AS3  methods that are called from FMIS SSAS code:
    --  pClient.call("verifyClient",  new VerifyClientHandler(pClient), pClient.verifyKey );  // IN:   ProtectVideoFromTheReplay\main.asc
    --  client.call( "asyncServerCall", new  handlerObject, msg );  // IN:  MethodCallWithNetConnection\main.asc
    --   client.call( "traceFromServer", null, this );  // IN:   LoadVariables\main.asc
    --  client.call("dataFromServer", null, {result:  result});   // IN:  WebService\main.asc

    Please post back if you find this helpful.

    Best regards,

    g

    Code snippets in 3 pieces:

    // FMIS SSAS in application.onConnect

    client.call("authorizeResult", null , result);

    // AS3 Top level app

    nc = new NetConnection();
    proxyListener = new  ProxyListener();
    ...
    nc.client = proxyListener;

    // AS3 ProxyListener.as

    public function authorizeResult( result:Object ):void
    {
    // your logic  here
    }

    July 11, 2009

    Hi Greg,

      Thank you for your quick (and detailed) reply!

      Your code confirms for me that a secondary class is definitely needed to act as a proxy in Flex for the FMS call I was looking for (since Flex makes use of AS3).  The real root cause of my problems stemmed from the fact that I'm still getting used to thinking about things a bit differently.  The real issue was that the method being invoked by the server on the client didn't exist in every client (for various reasons).  Once I got that nailed down, everything worked swimmingly.

      Thanks again for your help!  Have a great weekend!

    Cheers,

    Duncan