Action Script

Navigation:  Widget Designer > Nodes > Script Nodes >

Action Script

prev main next

Navigation:  Widget Designer > Nodes > Script Nodes >

Action Script

prev main next

Please wait. Due to its content this page might take a while to load...

The Action Script node allows triggering scripts with different events and actions. This action can be the change of a widget property, as well as a new package being received on a TCP, UDP or COM connection. Also available as trigger is the Phidget RFID, for executing scripts on a detected ID change.

Nearly all widget properties that are also available as object member properties can be inserted as trigger, multiple triggers are possible, too. A blue highlight provides you a visual indication when an action being detected and the script is performed.

The "Value" parameter also allows you to make use of the dedicated value of the action triggering the script.

This node can be found under Nodes > Scripts > Action

wd_nodes_scripts_action-script

Node Properties

Filter Page:
Select here the page on which the widget is located you want to add as a trigger. All windows and pages are available, the node is not limited to the page it is located on.

Action:
This drop-down offers you a list of all possible trigger actions. It includes all widgets and their properties of the page you selected above, as well as the Phidget RFID device and all set TCP, UDP and COM connections. Select one entry of the drop-down and add it to your list by pressing the "Add" button. Multiple triggers can be added, the Action Script node will listen to alterations of all elements in the list and perform its script as soon as it detects one.

It is a good workaround for triggers not listed in the drop-down, to use a Label for displaying the wished trigger and set the Action Script action to the Label text property. This way, even variables or values from input nodes can act as a trigger.

Script:
In the Script section you may enter commands to be executed when the according data is received. For a better overview, it is recommended to make use of Macros and Functions for sophisticated scripts.
The actual value of the action triggering the script is handed over with the "Value" parameter. "Value" is of the data type "object", so you have to convert it to the estimated data type before using it in the script for most applications.

The value of a TCP, UDP and COM package is committed as a list of integers, representing the decimal bytes of the whole package. Please also refer to the chapter Syntax TCP- / UDP- / Serial Messages for further information concerning byte transcription.

Example: The string "Hello World!" is represented by the byte list [72,101,108,108,111,32,87,111,114,108,100,33].

Examples

Example: Label Text

Task: Every time the text of Label1 changes, the respective text should be written in the DebugLogger, together with the current timestamp. For the timestamp, the global variable "Now" can be used.

Action: Label.Text

Script:

DebugMessage(Now + ": " + Value)

If you have for example three lines of a Japanese Haiku (by Matsuo Bashō) displayed in this Label one after the other, the resulting DebugLogger might look like this:

2017-10-25 12:37:22.187: iza saraba (an ancient pond)

2017-10-25 12:38:19.707: yukimi ni korobu (a frog jumps in)

2017-10-25 12:41:17.788: tokoromade (the splash of water)

 

Example 2: TCP Input Packet

Task: The Action Script node listens to TCP connection ID 1. The received packets should be analyzed, the header of the packets of interest is "WD!". The payload after the header contains text information and should be displayed on Label1.

Action: TcpConnection1.NewPacket

Script:

var byte_list = Value.ToList.Copy

if (byte_list[0] = 87) AND (byte_list[1] = 68) AND (byte_list[2] = 33) {

 byte_list.Remove(0)

 byte_list.Remove(0)

 byte_list.Remove(0)

 Label1.Text = byte_list.DecodeBytes

}

 

Node control

With Widget Designer version 6, all nodes support so called node commands. Node commands access functions (i.e methods) from a node and / or set a parameter (i.e. property).

Enter "node", followed by the according ID and a dot and a list will pop up showing all available commands for the node. For instance, Node1.TintColor.SetRGB(125,0,255), colors the node in purple.
In addition, the node properties with a parameter ID (the small superscript number) can be edited via the command Node1.SetParam(ID,new Value) or WDNodeSetParam(NodeID,ParamID,Value).