Server-Side ActionScript in Flash Media Server

Flash Media Server (Interactive version) has a language server named Server-Side ActionScript or ActionScript Communications (extension .asc). The powerful feature that allows multimedia applications in their way beyond a simple streaming.
Server-Side ActionScript is Adobe’s name for JavaScript 1.5, Flash Media Server has a JavaScript engine to build and run scripts.
Server-Side ActionScript is similar, but not identical, to ActionScript 1.0. Both languages are based on ECMAScript (ECMA-262) edition 3 language specification. Server-Side ActionScript runs in the Mozilla SpiderMonkey engine embedded in Flash Media Interactive Server. ActionScript 1.0 runs in AVM1 (ActionScript Virtual Machine 1) in Adobe Flash Player. SpiderMonkey implemented the ECMAScript specification exactly and Flash Player AVM1 did not. The biggest difference between Server-Side ActionScript and ActionScript 1.0 is that Server-Side ActionScript is case-sensitive.
So for those who already have knowledge of JavaScript, you can recycles it for use in Flash Media Server, you can use the most features and still have the unique features of Flash Media Server.

Let the first steps to use Server-Side ActionScript in Flash Media Server. One way to test your scripts using the fms_console is located in the path:

INSTALATION FOLDER\Adobe\Flash Media Server 4.5\webroot\swfs\fms_adminConsole.swf

If you have Adobe Flash Professional, you can open this file directly giving only two clicks, otherwise, open the browser. When opened, we have a screen like this:

fms_console_tela1

Tela inicial do fms_adminConsole.swf


Just enter the login and password that you determined at the time was installing Flash Media Server that should go to the following screen:
fms_console_tela2

Tela pos-login


This will be your best friend when developing applications with Flash / Flex and Flash Media Server. By default, Flash Media Server reads the following directory:

INSTALATION FOLDER\Adobe\Flash Media Server 4.5\applications

This path can be configured by modifying the line “VHOST.APPSDIR” in the following file:

INSTALATION FOLDER\Adobe\Flash Media Server 4.5\conf\fms.ini

We will create a directory called “teste”, and inside a file called “main.asc” with the following contents:

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");

Now the console will load our application by creating a new instance of it by selecting the combobox:

On the next screen is just “enter”

We should have the results of our trace in the text box as in the image:

fms_console_tela5

Resultado do trace


One recommendation I make is that you clean the screen before running the script again main.asc, simply click the Clear Log (1) Application and then Reload (2):

Some examples of what can be used with Server-Side ActionScript

Constants

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");
  3. const PI = 3.14;
  4. trace(PI);

Regular Expressions

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");
  3. myRe = /d(b+)d/g;
  4. myArray = myRe.exec("cdbbdbsbz");
  5. trace(myArray);

Functions

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");
  3. function teste()
  4. {
  5.     return "to na funcao o/";  
  6. }
  7. trace(teste());
  8.  
  9. function factorial(n)
  10. {
  11.    if ((n == 0) || (n == 1))
  12.       return 1;
  13.    else
  14.    {
  15.       var result = (n * factorial(n-1) );
  16.       return result;
  17.    }
  18. }
  19. trace(factorial(5));

Bbjects

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");
  3. var obj = {id:"teste",data:2,status:"ONLINE",type:"admin"}
  4. trace(obj);
  5. for(s in obj)
  6. {
  7.     trace(s +" - "+obj[s]);
  8. }

Array

javascript

  1. // ActionScript Communications Document
  2. trace("init app...");
  3. var arr = ["leo", "bruno", "wendel", "andre","juba"];
  4. trace(arr);
  5. function removeValueFromArray(arr, value)
  6. {
  7.     var len = arr.length;
  8.    
  9.     for(var i = len; i > -1; i--)
  10.     {
  11.         if(arr[i] === value)
  12.         {
  13.             arr.splice(i, 1);
  14.         }
  15.     }
  16.     return arr;
  17. }
  18. trace(removeValueFromArray(arr,"pam"));

Important notice, ONLY use these resources in the development environment. In production environment, you will drop everyone who is connected to its application. 😛

Reference:
Documentation Adobe Flash Media Server

Was this article helpful? feel free to make a donation and help keep the blog in the air
Adobe, Flash, Flash Media Server, JavaScript , ,

Leave a Reply