Insert
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
In this example, the AnalogInput might be given an instance name of “input1″, the Insert widget given a name of “insert1″. Set the Insert widget inputSource to “input1″, and the ClipControl widget inputSource to “insert1″. Your code can listen to and process the values from the Insert widget’s inputSource (the AnalogInput widget) with the following code on frame 1 of the timeline:
insert1.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 outputValue = inputValue * 2;
insert1.insertOutput(outputValue);
}
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 “insert1″ is multiplied by 2. The result is then sent to the output of the Insert widget with the statement:
insert1.insertOutput(outputValue);
The ClipControl widget receives this new processed value from the Insert widget. Alternatively, in a new feature, the Insert widget can have its output set by simply setting its variable outputValue. For example:
insert1.outputValue = 125;
This method is especially useful if you are using the tween function, which requires a property name to be used as on of the parameters. For example:
var myTween:Tween = new Tween(insert1, "outputValue", Elastic.easeOut, 0, 300, 3, true);
This Tween will set the output values of the Tween widget named “insert1″ from 0 to 300 over a period of 3 seconds, using the Elastic.easeOut curve. For more info in the Tween object in ActionScript:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/transitions/Tween.html
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 insert1 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 “input1″ and “input2″ respectively. Similarly, two Insert widgets are named “insert1″ and “insert2″. The ClipControl widget only needs to listen to one of the Insert widgets, and sets its inputSource to “insert1″.
insert1.insertInput = processInput;
insert2.insertInput = processInput;
var lastInsert1 = 0;
var lastInsert2 = 0;
function processInput(inputValue, id) {
if (id == "insert1") lastInsert1 = inputValue;
else if (id == "insert2") lastInsert2 = inputValue;
if (lastInsert1 > 500 && lastInsert2 > 500) insert1.insertOutput(200);
else insert1.insertOutput(100);
}
Example FLA to download: insertExample.fla.zip
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
- INVISIBLE: if set to “yes”, the widget will disappear when the Flash movie is run
- INPUT SOURCE the instance name of the source the widget listens to, e.g AnalogInput or DigitalInput. 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.
- DATA FILE: The name of the file in the directory of the Flash file that data logging values will be recorded into and played back from.
- PLAYBACK SPEED X: 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.
- PLAYBACK TRIGGER: 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.
- RECORD SAMPLE RATE: 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.
- RECORD SPARCE: 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.
Data logging Documentation
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 three values:
- data value
- milliseconds since the start of recording
- date and time stamp
For example, here are the first 5 data points from a recording:
362,31,Fri Mar 12 2010 10:54:04 AM
628,1195,Fri Mar 12 2010 10:54:05 AM
708,1260,Fri Mar 12 2010 10:54:05 AM
748,1312,Fri Mar 12 2010 10:54:05 AM
994,1376,Fri Mar 12 2010 10:54:05 AM
Last modified June 10th, 2010

