Use Server-Side ActionScript™ to write server-side code for an Adobe® Media Server application. You can use ServerSide ActionScript to control login procedures, control events, communicate with other servers, allow and disallow
users access to various server-side application resources, and let users update and share information.
Adobe Media Server server-side APIs
Server-Side ActionScript is Adobe’s name for JavaScript 1.5. Adobe Media Server has an embedded Java-Script engine
that compiles and executes server-side scripts. This Server-Side ActionScript Language Reference documents the Adobe
Media Server host environment classes and functions. You can also use core Java-Script classes, functions, statements,
and operators. For more information, see the Mozilla JavaScript documentation at
http://developer.mozilla.org/en/JavaScript.
1
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 Adobe Media 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 casesensitive.
Global functions
The following functions are available anywhere in a server-side script:
SignatureDescription
clearInterval()Stops a call to the setInterval() method.
getGlobal()Provides access to the global object from the secure.asc file while the file is loading.
load()Loads a Server-Side ActionScript file (ASC) or JavaScript file (JS) into the main.asc file.
protectObject()Protects the methods of an object from application code.
setAttributes()Prevents certain methods and properties from being enumerated, written, and deleted.
setInterval()Calls a function or method at a specified time interval until the clearInterval() method is called.
trace()Evaluates an expression and displays the value.
clearInterval()
clearInterval(intervalID)
Stops a call to the setInterval() method.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Availability
Flash Communication Server 1
Parameters
intervalID An identifier that contains the value returned by a previous call to the setInterval() method.
Example
The following example creates a function named callback() and passes it to the setInterval() method, which is
called every 1000 milliseconds and outputs the message
"interval called." The setInterval() method returns a
number that is assigned to the intervalID variable. The identifier lets you cancel a specific setInterval() call. In the
last line of code, the
function callback(){trace("interval called");}
var intervalID;
intervalID = setInterval(callback, 1000);
// sometime later
clearInterval(intervalID);
intervalID variable is passed to the clearInterval() method to cancel the setInterval() call.
getGlobal()
getGlobal()
2
Provides access to the global object from the secure.asc file while the file is loading. Use the getGlobal() function to
create protected system calls.
Availability
Flash Media Server 2
Details
Adobe Media Server has two script execution modes: secure and normal. In secure mode, only the secure.asc file (if it
exists) is loaded and evaluated—no other application scripts are loaded. The
getGlobal() and protectObject()
functions are available only in secure mode. These functions are very powerful because they provide complete access
to the script execution environment and let you create system objects. Once the secure.asc file is loaded, the server
switches to normal script execution mode until the application is unloaded.
To prevent inadvertent access to the global object, always hold its reference in a temporary variable (declared by var);
do not hold its reference in a member variable or a global variable.
Example
The following code gets a reference to the global object:
var global = getGlobal();
load()
load(filename)
Loads a Server-Side ActionScript file (ASC) or JavaScript file (JS) into the main.asc file. Call this function to load
ActionScript libraries. The loaded file is compiled and executed after the main.asc file is successfully loaded, compiled,
and executed, but before
application.onAppStart() is called. The path of the specified file is resolved relative to
the main.asc file.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Availability
Flash Communication Server 1
Parameters
filename A string indicating the relative path to a script file from the main.asc file.
Example
The following example loads the myLoadedFile.asc file:
load("myLoadedFile.asc");
protectObject()
protectObject(object)
Protects the methods of an object from application code. Application code cannot access or inspect the methods
directly. You can use this function only in the secure.asc file.
Availability
Flash Media Server 2
3
Parameters
object An object to protect.
Returns
An Object.
Details
After an object is protected, don’t reference it in global variables or make it a member of an accessible object. The object
returned by
protectObject() dispatches all method invocations to the underlying object but blocks access to
member data. As a result, you can’t enumerate or modify members directly. The protected object keeps an outstanding
reference to the underlying object, which ensures that the object is valid. The protected object follows normal reference
rules and exists while it is referred to.
Adobe Media Server has two script execution modes: secure and normal. In secure mode, only the secure.asc file (if it
exists) is loaded and evaluated—no other application scripts are loaded. The
getGlobal() and protectObject()
functions are available only in secure mode. These functions are very powerful because they provide complete access
to the script execution environment and let you create system objects. Once the secure.asc file is loaded, the server
switches to normal script execution mode until the application is unloaded.
Example
After secure.asc is executed, calls to load() are directed through the user-defined system call, as shown in the
following example:
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
var sysobj = {};
sysobj._load = load; // Hide the load function
load = null; // Make it unavailable unpriviliged code.
sysobj.load = function(fname){
// User-defined code to validate/modify fname
return this._load(fname);
}
// Grab the global object.
var global = getGlobal();
// Now protect sysobj and make it available as
// "system" globally. Also, set its attributes
// so that it is read-only and not deletable.
Prevents certain methods and properties from being enumerated, written, and deleted. In a server-side script, all
properties in an object are enumerable, writable, and deletable by default. Call
attributes of a property or to define constants.
Availability
Flash Media Server 2
Parameters
object An Object.
propName A string indicating the name of the property in the object parameter. Setting attributes on nonexistent
properties has no effect.
enumerable One of the following values: true, false, or null. Makes a property enumerable if true or
nonenumerable if
enumerations (
readonly One of the following values: true, false, or null. Makes a property read-only if true or writable if false;
null value leaves this attribute unchanged. Any attempt to assign a new value is ignored. Typically, you assign a value
a
false; a null value leaves this attribute unchanged. Nonenumerable properties are hidden from
forvariinobj).
to a property while the property is writable and then make the property read-only.
setAttributes() to change the default
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
permanent One of the following values: true, false, or null. Makes a property permanent (nondeletable) if true
or deletable if
calling
false; a null value leaves this attribute unchanged. Any attempt to delete a permanent property (by
deleteobj.prop) is ignored.
Example
The following code prevents the resolve() method from appearing in enumerations:
Calls a function or method at a specified time interval until the clearInterval() method is called. This method
allows a server-side script to run a routine. The
clearInterval() method to stop the routine.
setInterval() method returns a unique ID that you can pass to the
Note: Standard JavaScript supports an additional usage for the setInterval() method,
setInterval(stringToEvaluate, timeInterval), which is not supported by Server-Side ActionScript.
Availability
Flash Communication Server 1
Parameters
function A Function object.
object.method A method to call on object.
interval A number indicating the time in milliseconds between calls to function.
p1, ..., pN Optional parameters passed to function.
Returns
An integer that provides a unique ID for this call. If the interval is not set, returns -1.
Example
The following example uses an anonymous function to send the message "interval called" to the server log every
second:
The following example also uses an anonymous function to send the message “interval called” to the server log every
second, but it passes the message to the function as a parameter:
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
function callback1(){trace("interval called"); }
setInterval(callback1, 1000);
The following example also uses a named function, callback2(), to send the message "interval called" to the
server log, but it passes the message to the function as a parameter:
function callback2(s){
trace(s);
}
setInterval(callback2, 1000, "interval called");
The following example uses the second syntax:
var a = new Object();
a.displaying=displaying;
setInterval(a.displaying, 3000);
displaying = function(){
trace("Hello World");
}
The previous example calls the displaying() method every 3 seconds and sends the message "Hello World" to the
server log.
6
See also
clearInterval()
trace()
trace(expression)
Evaluates an expression and displays the value. You can use the trace() function to debug a script, to record
programming notes, or to display messages while testing a file. The
trace() function is similar to the alert()
function in JavaScript.
The expression appears in the Live Log panel of the Administration Console; it is also published to the
application.xx.log file located in a subdirectory of the RootInstall\logs folder. For example, if an application is called
myVideoApp, the application log for the default application instance would be located here:
RootInstall\logs\_defaultVHost_\myVideoApp\_definst_.
Availability
Flash Communication Server 1
Parameters
expression Any valid expression. The values in expression are converted to strings if possible.
Application class
Every instance of a Adobe Media Server application has an Application object, which is a single instance of the
Application class. You don’t need to use a constructor function to create an Application object; it is created
automatically when an application is instantiated by the server.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Use the Application object to accept and reject client connection attempts, to register and unregister classes and
proxies, and to manage the life cycle of an application. The Application object has callback functions that are invoked
when an application starts and stops and when a client connects and disconnects.
Availability
Flash Communication Server 1
Property summary
PropertyDescription
7
application.allowDebugA boolean value that lets administrators access an application with the Administration API
application.clientsRead-only; an Array object containing a list of all the clients connected to an application.
application.configProvides access to properties of the ApplicationObject element in the Application.xml
application.hostnameRead-only; the host name of the server for default virtual hosts; the virtual host name for all other
application.nameRead-only; the name of the application instance.
application.serverRead-only; the platform and version of the server.
approveDebugSession() method (true) or not (false).
configuration file.
virtual hosts.
Method summary
Method Description
application.acceptConnection()Accepts a connection call from a client to the server.
application.broadcastMsg()Broadcasts a message to all clients connected to an application instance.
application.clearSharedObjects()Deletes persistent shared objects files (FSO files) specified by the soPath parameter and
application.clearStreams()Clears recorded streams files associated with an application instance.
application.denyPeerLookup()Specifies to the server that a peer lookup request has been denied.
application.disconnect()Terminates a client connection to the application.
clears all properties from active shared objects (persistent and nonpersistent).
application.gc()Invokes the garbage collector to reclaim any unused resources for this application instance.
application.getStats()Returns statistics about an application.
application.redirectConnection()Rejects a connection and provides a redirect URL.
application.registerClass()Registers a constructor function that is used when deserializing an object of a certain class
application.registerProxy()Maps a method call to another function.
application.rejectConnection()Rejects the connection call from a client to the server.
application.sendPeerRedirect()When a peer issues a lookup for a target peer, this method sends the peer an Array of
application.shutdown()Unloads the application instance.
type.
addresses for the target peer.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Event handler summary
Event handlerDescription
application.onAppStart()Invoked when the server loads an application instance.
application.onAppStop()Invoked when the server is about to unload an application instance.
application.onConnect()Invoked when NetConnection.connect() is called from the client.
8
application.onConnectAccept()Invoked when a client successfully connects to an application; for use with version 2
application.onConnectReject()Invoked when a connection is rejected in an application that contains components.
application.onDisconnect()Invoked when a client disconnects from an application.
application.onPeerLookup()Invoked when the server receives a lookup request.
application.onPublish()Invoked when a client publishes a stream to an application.
application.onStatus()Invoked when the server encounters an error while processing a message that was targeted
application.onUnpublish()Invoked when a client stops publishing a stream to an application.
components only.
at this application instance.
application.acceptConnection()
application.acceptConnection(clientObj)
Accepts a connection call from a client to the server.
Availability
Flash Communication Server 1
Parameters
clientObj A Client object; a client to accept.
Details
When NetConnection.connect() is called from the client side, it passes a Client object to
application.onConnect() on the server. Call application.acceptConnection() in an
application.onConnect() event handler to accept a connection from a client. When this method is called,
NetConnection.onStatus() is invoked on the client with the info.code property set to
"NetConnection.Connect.Success".
You can use the application.acceptConnection() method outside an application.onConnect() event handler
to accept a client connection that had been placed in a pending state (for example, to verify a user name and password).
When you call this method, NetConnection.onStatus() is invoked on the client with the info.code property set
"NetConnection.Connect.Success". For more information, see the NetStatusEvent.info property in the
to
ActionScript 3.0 Language and Components Reference or the
NetConnection.onStatus() entry in the Adobe Media
Server ActionScript 2.0 Language Reference.
Note: When you use version 2 components, the last line (in order of execution) of the onConnect() handler should be
application.acceptConnection() or application.rejectConnection() (unless you’re leaving the
either
application in a pending state). Also, any logic that follows
placed in the
application.onConnectAccept() and application.onConnectReject() handlers, or it will be
acceptConnection() or rejectConnection() must be
ignored.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Example
The following server-side code accepts a client connection and traces the client ID:
Note: This example shows code from an application that does not use components.
application.allowDebug
application.allowDebug
A boolean value that lets administrators access an application with the Administration API approveDebugSession()
method (
streams in the Administration Console.
The default value for this property is false and is set in the Application.xml file:
true) or not (false). A debug connection lets administrators view information about shared objects and
9
Setting application.allowDebug to true in a server-side script overrides the value in the Application.xml file. To
view information in the Administration Console about the shared objects and streams in an application, add the
following line to your code:
application.allowDebug = true;
Availability
Flash Media Server 2
application.broadcastMsg()
application.broadcastMsg(cmd [, p1,..., pN])
Broadcasts a message to all clients connected to an application instance. To handle the message, the client must define
a handler on the NetConnection object with the same name as the
In ActionScript 2.0, define the method on the NetConnection object. In ActionScript 3.0, assign the
NetConnection.client property to an object on which callback methods are invoked. Define the method on that
object.
Availability
Flash Media Server 2
Parameters
cmd A string; the name of the a handler on the client-side NetConnection object.
cmd parameter.
p1,..., pN A string; messages to broadcast.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Example
The following server-side code sends a message to the client:
The following client-side ActionScript 2.0 code handles the message and outputs “Hello Client”:
nc = new NetConnection();
nc.serverMessage = function(msg){
trace(msg);
};
The following client-side ActionScript 3.0 code handles the message and outputs “Hello Client”:
var nc:NetConnection = new NetConnection()
var ncClient = new Object();
nc.client = ncClient;
ncClient.serverMessage = nc_serverMessage;
function nc_serverMessage(msg:String):void{
trace(msg);
}
application.clearSharedObjects()
application.clearSharedObjects(soPath)
10
Deletes persistent shared objects files (FSO files) specified by the soPath parameter and clears all properties from
active shared objects (persistent and nonpersistent). Even if you have deleted all the properties from a persistent shared
object, unless you call
clearSharedObjects(), the FSO file still exists on the server.
Availability
Flash Communication Server 1
Parameters
soPath A string indicating the Uniform Resource Identifier (URI) of a shared object.
The soPath parameter specifies the name of a shared object, which can include a slash (/) as a delimiter between
directories in the path. The last element in the path can contain wildcard patterns (for example, a question mark [?]
and an asterisk [*]) or a shared object name. The
application.clearSharedObjects() method traverses the shared
object hierarchy along the specified path and clears all the shared objects. Specifying a slash (/) clears all the shared
objects that are associated with an application instance.
If soPath matches a shared object that is currently active, all its properties are deleted, and a clear event is sent to all
subscribers of the shared object. If it is a persistent shared object, the persistent store is also cleared.
The following values are possible for the soPath parameter:
• / clears all local and persistent shared objects associated with the instance.
• /foo/bar clears the shared object /foo/bar; if bar is a directory name, no shared objects are deleted.
• /foo/bar/* clears all shared objects stored under the instance directory /foo/bar. If no persistent shared objects
are in use within this namespace, the bar directory is also deleted.
• /foo/bar/XX?? clears all shared objects that begin with XX, followed by any two characters. If a directory name
matches this specification, all the shared objects within this directory are cleared.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Returns
A boolean value of true if the shared object at the specified path was deleted; otherwise, false. If wildcard characters
are used to delete multiple files, the method returns
were successfully deleted; otherwise, it returns
true only if all the shared objects that match the wildcard pattern
false.
Example
The following example clears all the shared objects for an instance:
function onApplicationStop(){
application.clearSharedObjects("/");
}
application.clearStreams()
application.clearStreams(streamPath)
Clears recorded streams files associated with an application instance. You can use this method to clear a single stream,
all streams associated with the application instance, just those streams in a specific subdirectory of the application
instance, or just those streams whose names match a specified wildcard pattern.
If the clearStreams() method is invoked on a stream that is currently recording, the recorded file is set to length 0
(cleared), and the internal cached data is also cleared.
11
A call to application.clearStreams() invokes the Stream.onStatus() handler and passes it an information
object that contains information about the success or failure of the call.
Note: You can also use the Administration API removeApp() method to delete all the resources for a single application
instance.
Availability
Flash Communication Server 1
Parameters
streamPath A string indicating the Uniform Resource Identifier (URI) of a stream.
The streamPath parameter specifies the location and name of a stream relative to the directory of the application
instance. You can include a slash (/) as a delimiter between directories in the path. The last element in the path can
contain wildcard patterns (for example, a question mark [?] and an asterisk [*]) or a stream name. The
clearStreams() method traverses the stream hierarchy along the specified path and clears all the recorded streams
that match the given wildcard pattern. Specifying a slash clears all the streams that are associated with an application
instance.
To clear FLV, F4V, or MP3 files, precede the stream path with flv:, mp4:, or mp3:. When you specify flv: or mp3:
you don’t have to specify a file extension; .flv and .mp3 are implied. However, when you call
application.clearStreams("mp4:foo"), the server deletes any file with the name “foo” in an MPEG-4 container;
for example, foo.mp4, foo.mov, and foo.f4v. To delete a specific file, pass the file extension in the call; for example,
application.clearStreams("mp4:foo.f4v").
Note: If you don't precede the stream path with a file type, only FLV files are deleted.
The following examples show some possible values for the streamPath parameter:
• flv:/ clears all FLV streams associated with the application instance.
• mp3:/ clears all MP3 files associated with the application instance.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
• mp4:/ clears all F4V streams associated with the application instance (for example, foo.mp4, foo.f4v, and so on).
• mp4:foo.mp4 clears the foo.mp4 file.
• mp4:foo.mov clears the foo.mov file.
• mp3:/mozart/requiem clears the MP3 file named requiem.mp3 from the application instance’s /mozart
subdirectory.
• mp3:/mozart/* clears all MP3 files from the application instance’s /mozart subdirectory.
• /report clears the report.flv stream file from the application instance directory.
• /presentations/intro clears the recorded intro.flv stream file from the application instance’s /presentations
subdirectory; if
intro is a directory name, no streams are deleted.
• /presentations/* clears all FLV files from the application instance’s /presentations subdirectory. The
/presentation subdirectory is also deleted if no streams are used in this namespace.
• /presentations/report?? clears all FLV files that begin with “report,” followed by any two characters. If there
are directories within the given directory listing, the directories are cleared of any streams that match
report??.
Returns
A boolean value of true if the stream at the specified path was deleted; otherwise, false. If wildcard characters are
used to clear multiple stream files, the method returns
successfully deleted; otherwise, it returns
false.
true only if all the streams that match the wildcard pattern were
12
Example
The following example clears all recorded streams:
function onApplicationStop(){
application.clearStreams("/");
}
The following example clears all MP3 files from the application instance’s /disco subdirectory:
function onApplicationStop(){
application.clearStreams("mp3:/disco/*");
}
Removing all HDS segments
To remove all the existing HDS segments when the application unloads, you can use the clearOnAppStop tag as
shown below:
<JSEngine>
<ApplicationObject>
<config>
<clearOnAppStop>true</clearOnAppStop></config>
</ApplicationObject>
</JSEngine>
application.clients
application.clients
Read-only; an Array object containing a list of all the clients connected to an application. Each element in the array is
a reference to the Client object; use the
application.clients.length property to determine the number of users
connected to an application.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Do not use the index value of the clients array to identify users between calls, because the array is compacted when
users disconnect and the slots are reused by other Client objects.
Availability
Flash Communication Server 1
Example
The following example uses a for loop to iterate through each element in the application.clients array and calls
serverUpdate() method on each client:
the
for (i = 0; i < application.clients.length; i++){
application.clients[i].call("serverUpdate");
}
application.config
application.config
Provides access to properties of the ApplicationObject element in the Application.xml configuration file. To access
properties that you set in the configuration file, use the
password element, use the code application.config.password.
of the
application.config property. For example, to set the value
13
Availability
Flash Media Server 2
Example
Use this sample section from an Application.xml file for this example:
Read-only; the host name of the server for default virtual hosts; the virtual host name for all other virtual hosts.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
If an application is running on the default virtual host, and if a value is set in the ServerDomain element in the
Server.xml configuration file, the
element. If a value has not been set in the
application.hostname property contains the value set in the ServerDomain
ServerDomain element, the property is undefined.
If an application is running on any virtual host other than the default, the application.hostname property contains
the name of the virtual host.
Availability
Flash Communication Server 1.5
application.name
application.name
Read-only; the name of the application instance.
Availability
Flash Communication Server 1
Example
The following example checks the name property against a specific string before it executes some code:
16
if (application.name == "videomail/work"){
// Insert code here.
}
application.onAppStart()
application.onAppStart = function (){}
Invoked when the server first loads the application instance. Use this handler to initialize an application state. The
onAppStart() event is invoked only once during the lifetime of an application instance.
Availability
Flash Communication Server 1
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Example
application.onAppStart = function (){
trace ("*** sample_guestbook application start");
// Create a reference to a persistent shared object.
application.entries_so = SharedObject.get("entries_so", true);
// Prevent clients from updating the shared object.
application.entries_so.lock();
// Get the number of entries saved in the shared object
// and save it in application.lastEntry.
var maxprop = 0;
var soProperties = application.entries_so.getPropertyNames();
trace("soProperties:" + soProperties);
if (soProperties == null) {
application.lastEntry = 0;
} else {
for (var prop in soProperties) {
maxprop = Math.max (parseInt(prop), maxprop);
trace("maxprop " + maxprop);
}
application.lastEntry = maxprop+1;
}
// Allow clients to update the shared object.
application.entries_so.unlock();
trace("*** onAppStart called.");
};
17
application.onAppStop()
application.onAppStop = function (info){}
Invoked when the server is about to unload an application instance. You can use onAppStop() to flush the application
state or to prevent the application from being unloaded.
Define a function that is executed when the event handler is invoked. If the function returns true, the application is
unloaded. If the function returns
handler, or if the return value is not a boolean value, the application is unloaded when the event is invoked.
The Adobe Media Server application passes an information object to the application.onAppStop() event. You can
use Server-Side ActionScript to look at this information object to decide what to do in the function you define. You
can also use the
application.onAppStop() event to notify users before shutdown.
If you use the Administration Console or the Server Administration API to unload a Adobe Media Server application,
application.onAppStop() is not invoked. Therefore you cannot use application.onAppStop() to tell users that
the application is exiting.
When an application doesn’t have incoming client connections, the server considers the application idle and unloads
it. To prevent this, define an
Availability
Flash Communication Server 1
false, the application is not unloaded. If you don’t define a function for this event
Application.onAppStop() handler that returns false.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Parameters
info An Object, called an information object, with properties that explain why the application is about to stop
running. The information object has a
Code propertyLevel propertyDescription
Application.ShutdownstatusThe application instance is about to shut down.
Application.GCstatusThe application instance is about to be destroyed by the server.
code property and a level property.
Returns
The value returned by the function you define, if any, or null. To unload the application, return true or any non-
false value. To refuse to unload the application, return false.
Example
The following example flushes the entries_so shared object when the application stops:
application.onAppStop = function (info){
trace("*** onAppStop called.");
if (info=="Application.Shutdown"){
application.entries_so.flush();
}
}
18
application.onConnect()
application.onConnect = function (clientObj [, p1, ..., pN]){}
Invoked when NetConnection.connect() is called from the client. This handler is passed a Client object
representing the connecting client. Use the Client object to perform actions on the client in the handler. For example,
use this function to accept, reject, or redirect a client connection, perform authentication, define methods on the Client
object to be called remotely from
Client.writeAccess properties to determine client access rights to server-side objects.
When performing authentication, all of the information required for authentication should be sent from the
NetConnection.connect() method to the onConnect() handler as parameters (p1..., pN).
If you don’t define an onConnect() handler, connections are accepted by default.
If there are several simultaneous connection requests for an application, the server serializes the requests so that only
application.onConnect() handler is executed at a time. It’s a good idea to write code for the
one
application.onConnect() function that is executed quickly to prevent a long connection time for clients.
Note: When you are using the version 2 component framework (that is, when you are loading the components.asc file in
your server-side script file), you must use the
Availability
Flash Communication Server 1
Parameters
clientObj A Client object. This object contains information about the client that is connecting to the application.
NetConnection.call(), and set the Client.readAccess and
application.onConnectAccept() method to accept client connections.
p1 ..., pNOptional parameters passed to the application.onConnect() handler from the client-side
NetConnection.connect() method when a client connects to the application.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Returns
A boolean value; true causes the server to accept the connection; false causes the server to reject the connection.
When true is returned, NetConnection.onStatus() is invoked on the client with info.code set to
"NetConnection.Connect.Success". When false is returned, NetConnection.onStatus() is invoked on the
client with
info.code set to "NetConnection.Connect.Rejected".
If null or no value is returned, the server puts the client in a pending state and the client can’t receive or send messages.
If the client is put in a pending state, you must call
application.rejectConnection() at a later time to accept or reject the connection. For example, you can perform
external authentication by making a NetConnection call in your
application server and having the reply handler call
application.rejectConnection(), depending on the information received by the reply handler.
application.acceptConnection() or
application.onConnect() event handler to an
application.acceptConnection() or
You can also call application.acceptConnection() or application.rejectConnection() in the
application.onConnect() event handler. If you do, any value returned by the function is ignored.
Note: Returning 1 or 0 is not the same as returning true or false. The values 1 and 0 are treated the same as any other
integers and do not accept or reject a connection.
19
NetConnection.connect()
NetConnection.onStatus(info)
info.code == NetConnection.Connect.Success
application.acceptConnection()
application.onConnect(clientObject)
return true
or call
return false
NetConnection.onStatus(info)
info.code == NetConnection.Connect.Rejected
application.rejectConnection()
or call
return null
or don’t return a value
places application in a pending state
A. Client-side ActionScript B. Server-Side ActionScript
A
B
Example
The following examples show three ways to accept or reject a connection in the onConnect() handler:
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
(Usage 1)
application.onConnect = function (clientObj [, p1, ..., pN]){
// Insert code here to call methods that do authentication.
// Returning null puts the client in a pending state.
return null;
};
(Usage 2)
application.onConnect = function (clientObj [, p1, ..., pN]){
// Insert code here to call methods that do authentication.
// The following code accepts the connection:
application.acceptConnection(clientObj);
};
(Usage 3)
application.onConnect = function (clientObj [, p1, ..., pN])
{
// Insert code here to call methods that do authentication.
// The following code accepts the connection by returning true:
return true;
};
The following example verifies that the user has sent the password “XXXX”. If the password is sent, the user’s access
rights are modified and the user can complete the connection. In this case, the user can create or write to streams and
shared objects in the user’s own directory and can read or view any shared object or stream in this application instance.
20
// This code should be placed in the global scope.
application.onConnect = function (newClient, userName, password){
// Do all the application-specific connect logic.
if (password == "XXXX"){
newClient.writeAccess = "/" + userName;
this.acceptConnection(newClient);
} else {
var err = new Object();
err.message = "Invalid password";
this.rejectConnection(newClient, err);
}
};
If the password is incorrect, the user is rejected and an information object with a message property set to "Invalid
password" is returned to the client side. The object is assigned to infoObject.application. To access the message
property, use the following code on the client side:
ClientCom.onStatus = function (info.application.message){
trace(info.application.message);
// Prints "Invalid password"
// in the Output panel on the client side.
};
application.onConnectAccept()
application.onConnectAccept = function (clientObj [,p1, ..., pN]){}
Invoked when a client successfully connects to an application; for use with version 2 components only. Use
onConnectAccept() to handle the result of an accepted connection in an application that contains components.
Note: This component set is deprecated and not included with Adobe Media Server versions 4.0 and later. The
components are available from
www.adobe.com/go/ams_tools.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
If you don’t use the version 2 components framework (ActionScript 2.0 components), you can execute code in the
application.onConnect() handler after accepting or rejecting the connection. When you use the components
framework, however, any code that you want to execute after the connection is accepted or rejected must be placed in
application.onConnectAccept() and application.onConnectReject() event handlers. This architecture
the
allows all of the components to decide whether a connection is accepted or rejected.
Availability
Flash Media Server (with version 2 media components only).
Parameters
clientObj A Client object; the client connecting to the application.
p1, ..., pN Optional parameters passed to the application.onConnectAccept() method. These parameters are
passed from the client-side
NetConnection.connect() method when a client connects to the application; they can
be any ActionScript data type.
Example
The following example is client-side code:
nc = new NetConnection();
nc.connect("rtmp:/test","jlopes");
// Code is in onConnectAccept and onConnectReject statements
// because components are used.
application.onConnectAccept = function(client, username){
trace("Connection accepted for "+username);
client.call("doSomething",null);
}
application.onConnectReject = function(client, username){
trace("Connection rejected for "+username);
}
22
application.onConnectReject()
application.onConnectReject = function (clientObj [,p1, ..., pN]){}
Invoked when a connection is rejected in an application that contains components.
Note: This component set is deprecated and not included with Flash Media Server versions 4.0 and later. The components
are available from
If you don’t use the version 2 components framework, you can execute code in the application.onConnect()
handler after accepting or rejecting a connection. When you use the components framework, however, any code that
you want to execute after the connection is accepted or rejected must be placed in the
application.onConnectAccept() and application.onConnectReject() framework event handlers. This
architecture allows all of the components to decide whether a connection is accepted or rejected.
Availability
Flash Media Server (with version 2 components only)
Parameters
clientObj A Client object; the client connecting to the application.
p1, ..., pN Optional parameters passed to the application.onConnectReject() handler. These parameters are
passed from the client-side
Example
The following example is client-side code that you can use for an application:
www.adobe.com/go/ams_tools.
NetConnection.connect() method when a client connects to the application.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
nc = new NetConnection();
nc.connect("rtmp:/test","jlopes");
application.onConnectAccept = function(client, username){
trace("Connection accepted for "+username);
client.call("doSomething",null);
}
application.onConnectReject = function(client, username){
trace("Connection rejected for "+username);
}
23
application.onDisconnect()
application.onDisconnect = function (clientObj){}
Invoked when a client disconnects from an application. Use this event handler to flush any client state information or
to notify other users that a user is leaving the application. This handler is optional.
Note: After a client has disconnected from an application, you cannot use this method to send data back to that
disconnected client.
Availability
Flash Communication Server 1
Parameters
clientObj A Client object; a client disconnecting from the application.
Returns
Server ignores any return value.
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Example
This example notifies all connected clients when a client disconnects from an application. The client-side FLA file
contains an input text field called
connectButton. The user enters their name in the input text field. The client-side code passes the name to the server
NetConnection.connect() call, as follows:
in the
nc = new NetConnection();
nc.userDisconnects = function(name) {
statusText.text = name + ": disconnected";
}
nc.onStatus = function(info){
nameText, a dynamic text field called statusText, and a button called
The server-side onConnect() handler receives the user name from the client-side code and assigns it to a property of
the Client object. The server passes the Client object to the
the application. The
Client.call() method inside the onDisconnect() handler calls the userDisconnects
onDisconnect() handler when a client disconnects from
method on the client and passes it the name of the disconnecting client. The client displays the name of the
disconnected user.
24
application.onConnect = function(client, name){
client.name = name;
trace(client.name + ": onConnect");
return true;
}
application.onDisconnect = function(client){
for (var i = 0; i < application.clients.length; i++){
application.clients[i].call("userDisconnects", null, client.name);
}
trace(client.name + ": onDisconnect");
}
Note: To pass optional parameters to the Client.call() method, pass null for the second (responseObject)
parameter.
application.onPeerLookup()
application.onPeerLookup = function (event:Object){}
Invoked when Adobe Media Server receives a request from a client to connect to another peer. The initiating peer is
the peer that makes the request. The target peer is the peer to which the initiating peer wants to connect. Both the
initiating peer and the target peer can be connected directly to the server or remote. To reply to the peer lookup
request, call
Availability
Flash Media Server 4.5
application.sendPeerRedirect().
Parameters
event Object; contains information about the intiating peer and the target peer. Pass the event object in calls to
application.sendPeerRedirect(). Pass the event.tag object in calls to Client.introducePeer().
The event object contains the following properties:
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
PropertyData typeDescription
25
targetPeerIDStringThe peerID of the target peer. The initiating peer is attempting to
initiatorAddress StringThe IP address of the initiating client. Send redirect information to
tagByteArrayA value that uniquely identifies this lookup request.
interfaceIDNumberIdentifies the RTMFP interface on which the request was received.
look up and connect to the target peer.
this address.
Example
For an example of distributing peer lookup requests across multiple servers, see Distribute peer lookup requests across
application.onPublish = function (clientObj, streamObj){}
Invoked when a client publishes a stream to an application. Use this event handler to send traffic to other servers when
you’re building a large-scale live broadcasting application; this is called multipoint publishing. For example, you can
support subscribers in multiple geographic locations by sending traffic from the origin server (Server A) in one city to
two origin servers in two different cities (Server B and Server C). The following is the workflow for such a scenario:
1 A client publisher connects to Server A and starts publishing.
2 Server A receives notifications from the event handler application.onPublish() in a server-side script.
3 Inside the onPublish() handler, create two NetStream objects to Server B and Server C.
4 Call the NetStream.publish() method to redirect the publishing data from Server A to Server B and Server C.
5 Subscribers connecting to Server B and Server C get the same live stream.
In this example, the publishing client connects and publishes only to Server A. The rest of the data flow is handled by
logic in the server-side script.
Note: You cannot change Client object properties in this handler.
Availability
Flash Media Server 3
Parameters
clientObj A Client object; the client publishing the stream to the application.
streamObj A Stream object; the stream being published to the application.
Returns
Server ignores any return value.
application.onStatus()
application.onStatus = function (infoObject){}
Last updated 9/20/2013
SERVER-SIDE ACTIONSCRIPT LANGUAGE REFERENCE FOR ADOBE MEDIA SERVER 5.0.3
Server-Side ActionScript Language Reference
Invoked when the server encounters an error while processing a message that was targeted at this application instance.
application.onStatus() handler handles any Stream.onStatus() or NetConnection.onStatus()
The
messages that don’t find handlers. Also, there are a few status calls that come only to
application.onStatus().
Availability
Flash Communication Server 1
Parameters
infoObject An Object with code and level properties that contain information about the status of an application.
Some information objects also have
details and description properties.The following table describes the
information object property values:
Code propertyLevel propertyDescription
Application.Script.ErrorerrorThe ActionScript engine has encountered a runtime error.
This information object also has the following properties:
• filename: name of the offending ASC file.
• lineno: line number where the error occurred.
• linebuf: source code of the offending line.
26
Application.Script.WarningwarningThe ActionScript engine has encountered a runtime warning.
This information object also has the following properties:
• filename: name of the offending ASC file.
• lineno: line number where the error occurred.
• linebuf: source code of the offending line.
Application.Resource.LowMemorywarningThe ActionScript engine is low on runtime memory. This provides an
opportunity for the application instance to free some resources or to
take suitable action.
If the application instance runs out of memory, it is unloaded and all
users are disconnected. In this state, the server does not invoke the
application.onDisconnect() event handler or the
application.onAppStop() event handler.
Rejects a connection and provides a redirect URL. You must write logic in the NetConnection.onStatus() handler
that detects redirection and passes the new connection URL to the
NetConnection.connect() method.
When this method is called, NetConnection.onStatus() is invoked on the client and passed an information object
with the following values:
PropertyValue
info.code"NetConnection.Connect.Rejected"
info.descriptionThe value passed in the description parameter; if no value is passed in the parameter, the default value is
info.ex.code302
info.ex.redirectThe new connection URL
info.level"Error"
"Connection failed"
Availability
Flash Media Server 3
Parameters
clientObj A Client object specifying a client to reject.
url A string specifying the new connection URL.
Note: If you omit this parameter, rejectConnection() is called instead.
description A string that lets you provide more information when a connection is redirected.
errorObj An object of any type that is sent to the client, explaining the reason for rejection. The errorObj object is
available in client-side scripts as the
NetConnection.onStatus() call when the connection is rejected.
application property of the information object that is passed to the
Last updated 9/20/2013
Loading...
+ 142 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.