Provides a mechanism for inserting ActionScript code between widgets

The Code widget is used to insert ActionScript code between two widgets. It allows the designer’s code to easily receive values from Code’s inputSource, process them, and then output the resulting new values via the output of Code. Other widgets can then set their inputSource to receive input from the Code widget.

Note: Previously, the Code widget had logging capabilities. These have now been moved to the Logger widget.

Example 1

You can create a set up such as this:

AnalogInput -> Code -> ClipControl

In this example, the AnalogInput might be given an instance name of “input0”, the Code widget given a name of “myCode”. Set the Code widget inputSource to “input0”, and the ClipControl widget inputSource to “myCode”. Your code can listen to and process the values from the Code widget’s inputSource (the AnalogIn widget) with the following code on frame 1 of the timeline:

myCode.insertInput = processInput;
function processInput(inputValue, id) {
     // inputValue is the value from Code widget's inputSource
     // id is the instance name of the Code widget sending the value
     var newValue = inputValue * 2;
     myCode.outputValue = newValue;

Where myCode is the instance name of the Code widget, and “processInput” is the name of a function that will receive the values. In this simple example, the value received from the AnalogInput widget into the inputSource of the Code widget called “myCode” is multiplied by 2. The result is then sent to the output of the Code widget with the statement:

myCode.outputValue = newValue;

The ClipControl widget receives this new processed value from the Code widget.

Example 2

AnalogInput -> Code -> ClipControl
AnalogInput -> Code

In a more complex example of using the Code widget, the values from two different AnalogInputs are compared, and only if both have a value greater than 500 is the output of insert0 set to 200, otherwise the output is set to 100. The “id” parameter in the function is used to distinguish between the two inputs, using a single function to process both. In this example, the AnalogInputs are name “input0” and “input1” respectively. Similarly, two Code widgets are named “myCode0” and “myCode1”. The ClipControl widget only needs to listen to one of the Code widgets, and sets its inputSource to “myCode0”.

myCode0.insertInput = processInput;
myCode1.insertInput = processInput;

var last0 = 0;
var last1 = 0;

function processInput(inputValue, id) {
    if (id == "myCode0") last0 = inputValue;
    else if (id == "myCode1") last1 = inputValue;

    if (last0 > 500 && last1 > 500) myCode0.outputValue = 200;
    else myCode0.outputValue = 100;

On Screen Features

  • in – The value received from the inputSource
  • out – The value set by the code. By default, the IN value is passed directly to the OUT


  • inputSource – the instance name of the source the widget listens to, e.g AnalogIn or DigitalIn.
  • invisible – if set to “yes”, the widget will disappear when the Flash movie is run

Code Interface

These are the code interfaces available for the Code widget:


Where value is sent to the output of the Code widget 

Last modified December 26th, 2013