ssScript Overview

ssScript is an AS3-only class that is used to setup communications between JScript modules and Flash. The JScript code can call ActionScript through the jsScript.execute method. From ActionScript you set the function that will handle this call from JScript by calling ssScript.addCallHandler. One JScript module is tied to one call handler.

Calls made to ActionScript from JScript can pass any number of parameters and the parameters can be of any type supported by (or that can be converted by) JSON. Unlike most other SWF Studio API calls, arguments passed to jsScript.execute do not have to be properties of an object, but can be. Nested data types are supported. Visit the JSON web site for more details about data type support.

The call handler function can return a value to the calling JScript module. This return value also uses JSON.

Note: While nested objects are supported, cyclical references (child object referencing a parent object) will cause an endless loop, since JSON cannot handle this condition.


Examples:

In the following example we create a function that will handle calls from our JScript module we've named "myModule". See ssCore.Script Overview for information about creating script modules. We then add our function as a call handler for the myModule script module. The call handler function below displays the values of the properties of the object that is passed along with the data type information.

function myModuleCallHandler(obj:Object):void
{
    ssDebug.trace(obj.prop1);

    ssDebug.trace(typeof(obj.prop1));

    ssDebug.trace(obj.prop2);

    ssDebug.trace(typeof(obj.prop2));

    return true;
}

ssScript.addCallHandler({module:"myModule", handler:myModuleCallHandler});

The following is an example of JScript code that calls the call handler above. Note that any native data type supported by JSON (see json.org) can be passed to the callhandler function and returned back by the handler.

var bool = jsScript.execute({prop1:"A string passed from JScript", prop2:10});

trace(bool);

trace(typeof(bool));