Flash Media Server 3: calling a function from ASC to AS3 (Server – Client interaction)

By | July 15, 2012

I had quite a hard time figuring out how to call a function hosted on FMS (an .asc file) and how to call a function on the client from the server. I’m new to FMS (Flash Media Server) and there is not a ton of documentation, updated, for ActionScript 3.0.


So here is a simple example of interaction between server and client function. Obviously you first have to install FMS on your computer (I used the free developer version of FMS 3).


Installed? Let’s start: we will need two files, a document class for your .fla and an .asc (server side ActionScript) file.

.as file (document class): Interaction.as

import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.net.Responder;
import flash.events.NetStatusEvent;

public class Interaction extends MovieClip
// Responder for call to server's
private var myResponder:Responder = new Responder(onReply);
private var nc:NetConnection;

public function Interaction():void
nc = new NetConnection();
nc.addEventListener( NetStatusEvent.NET_STATUS, netStatusHandler );

// Connect to the server.

//Allow method within th class to be called by the server side script
nc.client = this;


//Handle NetStatus
private function netStatusHandler( event:NetStatusEvent ):void
switch( event.info.code )
// Successfully connected to FMS, execute function
case "NetConnection.Connect.Success":

public function callServerSideF():void
//Call a server side function written on an .ASC file
nc.call("callFromClient", myResponder, "Server");

public function calledByServerSide(msg:String):void
//Function called by an .ASC file
trace("ASC have to say :"+msg);

// Responder function for nc.call()
private function onReply(result:Object):void
trace("Client have to say " + result);

Now the .asc file: main.asc

//Application is launched
application.onAppStart = function()
/* Allow debugging */
this.allowDebug = true;

//Client is connected
application.onConnect = function( client )

//Accept the connection
application.acceptConnection( client );

//Call the function calledByServerSide from AS3
application.clients[0].call( "calledByServerSide", null, "Hello Client :-)");

// Define new client function for a nc.call().
client.callFromClient = function( helloStr ) {
return "Hello Mr " + helloStr + ":-D~";

//Client disconnected
application.onDisconnect = function( client )
//Trace on the FMS Application console
trace( client+" is disconnected" );

Copy main.asc on your FMS application folder (I called it /Interaction/).


I was helped by a tutorial made by ‘Newtriks’ and published in WebDesigner magazine (files are available to download, issue 137).

Download the example.


0 Kudos

11 thoughts on “Flash Media Server 3: calling a function from ASC to AS3 (Server – Client interaction)

  1. Ahmet Post author

    Hi Simon,
    that was really the minimum I could do, your tutorial was a great help!

  2. Pingback: A Web Technologist Adventure » Blog Archive » A Chat with FMS 3 coded in ActionScript 3.0

  3. melissa

    Thanks so much for the missing link! Finally, my project has turned a corner.
    One thing I’m not clear on is the use of clients[0] in the server side code. If there are multiple clients, what happens?

  4. Alex

    thx Ahmet!

    This thread helped a lot!
    Much better as the .call()-documentation from Adobe

  5. Pingback: A Chat with FMS 3 coded in ActionScript 3.0 | Random.Thinking.ToString();