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]
// ActionScript Communications Document
trace(“init app…”);
[/javascript]
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]
// ActionScript Communications Document
trace(“init app…”);
const PI = 3.14;
trace(PI);
[/javascript]

Regular Expressions

[javascript]
// ActionScript Communications Document
trace(“init app…”);
myRe = /d(b+)d/g;
myArray = myRe.exec(“cdbbdbsbz”);
trace(myArray);
[/javascript]

Functions

[javascript]
// ActionScript Communications Document
trace(“init app…”);
function teste()
{
return “to na funcao o/”;
}
trace(teste());

function factorial(n)
{
if ((n == 0) || (n == 1))
return 1;
else
{
var result = (n * factorial(n-1) );
return result;
}
}
trace(factorial(5));
[/javascript]

Bbjects

[javascript]
// ActionScript Communications Document
trace(“init app…”);
var obj = {id:”teste”,data:2,status:”ONLINE”,type:”admin”}
trace(obj);
for(s in obj)
{
trace(s +” – “+obj[s]);
}
[/javascript]

Array

[javascript]
// ActionScript Communications Document
trace(“init app…”);
var arr = [“leo”, “bruno”, “wendel”, “andre”,”juba”];
trace(arr);
function removeValueFromArray(arr, value)
{
var len = arr.length;

for(var i = len; i > -1; i–)
{
if(arr[i] === value)
{
arr.splice(i, 1);
}
}
return arr;
}
trace(removeValueFromArray(arr,”pam”));
[/javascript]

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