Script Overview

The Script commands enable you to load and run JScript to add functionality to your application/screensaver. The scripts can be loaded through a Flash variable or an external script file.

To begin you create a script module. You then load or add the script to the module. Then you can call any function within the script from Flash in your application/screensaver. You can pass parameters to a script function in the same manner that you pass parameters to a SWF Studio command. When the function returns, data can be passed back to the callback function you specified. The callback function will receive an object that will contain the data, in the same way all other SWF Studio commands return data. The data is always a string and the parameter name is "result".

When you make a call to a function in your module the data you pass is evaluated before being passed to the JScript function. Because of this all backslashes specified as data being passed need to be escaped twice. The escape character is a backslash so if you are escaping a character, such as a newline (\n) you will need to double-escape the backslash, for example \\n. To make this process easier there is an optional parameter for any call to a function on a JScript module called escapeBackslashes. If you set this property to true the SWF Studio player will escape the backslashes for you so you don't have to double-escape them.

Below is an example of how to use JScript from ActionScript. We create a script module called "JSActions" and want to call a function named "filterText". Our JScript is sitting in a file called "file.js" located next to our application. We'll pass some text to the JScript function and it will return some text that will be stored in a textfield.

ssCore.Script.create({module:'JSActions', language:'jscript'}, {callback:'scriptCreated'});

function scriptCreated(return_obj, callback_obj, error_obj)
{
    ssCore.Script.loadCode({module:'JSActions', path:'startdir://file.js'}, {callback:'codeLoaded'});
}

function codeLoaded(return_obj, callback_obj, error_obj)
{
    ssCore.JSActions.filterText({text:'c:\\folder\\file.txt',escapeBackslashes:true}, {callback:'fnReturn'});
}

function fnReturn(return_obj, callback_obj, error_obj)
{
    ourTextfield.text = return_obj.result;
}

And here is an example of the JScript code that could be inside the file called "file.js":

function filterText(obj)
{
    var oldText_str = obj.text;
    var newText_str = oldText_str.substr(oldText_str.lastIndexOf('\\') + 1);
    return newText_str;
}

That example does not demonstrate the power of JScript but it is meant to show the process by which you can use JScript in your application/screensaver.

You can also add script to a module instead of loading it from a file, or as a way of adding more script to an existing script module.

Included in the JScript module is a command called jsCommand. jsCommand is a method you can use to execute SWF Studio commands from JScript code. Callbacks are not necessary with jsCommand because jsCommand returns an object with data immediately.

The following code executes a call to the ADO plugin to retrieve 10 rows of data from a database.

var r = jsCommand('ADO.getRows', {rows:10});
trace(r.result); // This displays in the SWF Studio Trace tab.

You can even load and run scripts at runtime. This means that even after your application/screensaver is built and running you can edit and load code. This can signficantly decrease debugging time.

For more information about scripting, see the JScript Overview.

JScript supports regular expressions (RegExp), which enable you to create simple or complex, fast string searching and filtering. You can also create references to ActiveX objects to add even more functionality to your SWF Studio application/screensaver. For more JScript-specific features visit Microsoft's Scripting pages.

You can also use VBScript by specifying so when you create the script module. However, there is no jsCommand equivalent in VBScript.

In a VBScript module, functions that are called from Flash must contain one parameter. The parameter is a Collection, whose items correspond to the properties set on the parameters object that is passed. Even if no properties are set, or no object is passed in the Flash call, the VBScript function must have one parameter.