The following functions are available anywhere in a server-side script:

Signature

Description

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.

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 intervalID variable is passed to the clearInterval() method to cancel the setInterval() call.

 function callback(){trace("interval called");} 
 var intervalID;  
 intervalID = setInterval(callback, 1000);  
 // sometime later  
 clearInterval(intervalID);

getGlobal()

 getGlobal()

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.

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

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:

 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. 
  
 global["system"] = protectObject(sysobj); 
  
 setAttributes(global, "system", false, true, true); 
  
 // Now add a global load() function for compatibility. 
 // Make it read-only and nondeletable. 
  
 global["load"] = function(path){ 
     return system.load(path); 
 } 
  
 setAttributes(global, "load", false, true, true);

See also

setAttributes()

 setAttributes(object, propName, enumerable, readonly, permanent)

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 setAttributes() to change the default 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 false; a null value leaves this attribute unchanged. Nonenumerable properties are hidden from enumerations (forvariinobj).

readonly

One of the following values: true, false, or null. Makes a property read-only if true or writable if false; a null value leaves this attribute unchanged. Any attempt to assign a new value is ignored. Typically, you assign a value to a property while the property is writable and then make the property read-only.

permanent

One of the following values: true, false, or null. Makes a property permanent (nondeletable) if true or deletable if false; a null value leaves this attribute unchanged. Any attempt to delete a permanent property (by calling deleteobj.prop) is ignored.

Example

The following code prevents the resolve() method from appearing in enumerations:

 Object.prototype.__resolve = function(methodName){ ... }; 
 setAttributes(Object.prototype, "__resolve", false, null, null);

The following example creates three constants on a Constants object and makes them permanent and read-only:

 Constants.KILO = 1000;  
 setAttributes(Constants, "KILO", null, true, true); 
 Constants.MEGA = 1000*Constants.KILO;  
 setAttributes(Constants, "MEGA", null, true, true); 
 Constants.GIGA = 1000*Constants.MEGA; setAttributes(Constants, "GIGA", null, true, true);

setInterval()

 setInterval(function, interval[, p1, ..., pN]) 
 setInterval(object.method, interval[, p1, ..., pN])

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 setInterval() method returns a unique ID that you can pass to the clearInterval() method to stop the routine.

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:

 setInterval(function(){trace("interval called");}, 1000);

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:

 setInterval(function(s){trace(s);}, 1000, "interval called");

The following example uses a named function, callback1(), to send the message “interval called” to the server log:

 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.

See also

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.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy