Insert

THIS WIDGET HAS BEEN RENAMED TO CODE

Provides a mechanism for inserting ActionScript code into the widget signal path

The Insert widget is used to insert ActionScript code between two widgets. It allows the designer’s code to easily receive values from Insert’s inputSource, process them, and then output the resulting new values via the output of Insert. Other widgets can then set their inputSource to receive input from the Insert widget. For example, you might create a set up such as this:

AnalogInput -> Insert -> ClipControl

Example 1

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

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

Where insert1 is the instance name of the Insert 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 Insert widget called “insert0” is multiplied by 2. The result is then sent to the output of the Insert widget with the statement:

insert0.outputValue = newValue;

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

Example 2

In a more complex example of using the Insert 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 Insert widgets are named “insert0” and “insert1”. The ClipControl widget only needs to listen to one of the Insert widgets, and sets its inputSource to “insert0”.

insert0.insertInput = processInput;
insert1.insertInput = processInput;

var lastInsert0 = 0;
var lastInsert1 = 0;

function processInput(inputValue, id) {
    if (id == "insert0") lastInsert0 = inputValue;
    else if (id == "insert1") lastInsert1 = inputValue;

    if (lastInsert0 > 500 && lastInsert1 > 500) insert0.outputValue = 200;
    else insert0.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
  • record button – Starts and stops recording of values from the inputSource (including values feed by ActionScript via insertOutput())
  • play button – Plays back values from the “dataFile” as set in the parameters. Values can be processed by ActionScript using the insertInput function.

Parameters

  • dataFile – The name of the file in the directory of the Flash file that data logging values will be recorded into and played back from.
  • inputSource – the instance name of the source the widget listens to, e.g AnalogIn or DigitalIn. Note: Insert can be used as an input to other widgets. Give the Insert widget an instance name and use this as the INPUT SOURCE for the widget using Insert as its input.
  • invisible – if set to “yes”, the widget will disappear when the Flash movie is run
  • playbackLoop – If set to true, log playback will loop forever.
  • playbackSpeedX – A multiplier for the speed of playback for data logging. For example if playbackSpeedX is set to 2, the values will play back in sequence at twice the rate that they were recorded. Numbers less than 1 can be used to play back at speeds slower than real time – e.g. a value of 0.5 would play the sequence of values at half speed.
  • playbackTrigger – If set to true, values from the inputSource will not be processed normally, but instead the widget will begin playback of the data log values in in the dataFile when the threshold of 500 is reached.
  • recordSampleRate – This number determines how often data log values will be recorded, in milliseconds. For example, if set to 30, values will be recorded every 30 thousandths of a second (about 30 times per second). Or if set to 3000, then a value will be recorded every 3 seconds.
  • recordSparse – If set to true, data log values will only be recorded when they change. So if the same value came into the Insert widget for 10 seconds, no data would be recorded until after a different value came in. Setting this will help keep the dataFile smaller, and playback will be exactly the same since each data value is played back according to its time-stamp.

Code Interface

These are the code interfaces available for the Insert widget:

insertInstance.insertOutput(value);

Where value is sent to the output of the Insert widget

insertInstance.startPlay();

When called, the Insert widget will start playing a recorded log.

insertInstance.stopPlay();

When called, the Insert widget will stop playing a recorded log.

insertInstance.startRecord();

When called, the Insert widget will start recording a log.

insertInstance.stopRecord();

When called, the Insert widget will stop recording a log.

Data logging notes

Insert has the capability for data logging and playback. Time-stamped values from the inputSource can be recorded with the record button and saved to a file. The values in the file can later be played back with the same timing as they occurred, or at any other speed. Playback can also be triggered when input values rise above a certain threshold.

The recorded values and time-stamps are stored in a comma separated file that can be imported into a spreadsheet – each data point is on a line in the file and contains four values:

  • data value
  • milliseconds since the start of recording
  • date and time stamp
  • name of the widget that created the log

For example, here are the first 5 data points from a recording:

0,31,2011-03-25 17:51:33:635,insert0
184,1362,2011-03-25 17:51:34:965,insert0
347,1431,2011-03-25 17:51:35:034,insert0
490,1468,2011-03-25 17:51:35:071,insert0
582,1493,2011-03-25 17:51:35:096,insert0
643,1531,2011-03-25 17:51:35:134,insert0

 


Last modified July 15th, 2013