How to add processing of pressings for several objects in one AddListener structure?
At the moment each interface item needs its own listener:
The possibility of reference to the data is achieved by sending the 4th parameter in the AddListener method:
You can learn the name of each item pressed or subscribe for pressings on all items in the project using the following instructions.
// array of items
var gRegisters = [
{item: IR.GetItem("Page 1").GetItem("1")},
{item: IR.GetItem("Page 1").GetItem("2")},
{item: IR.GetItem("Page 1").GetItem("3")},
];
function OnPress()
{
// when we do something when pressing of an array item, this. - an indicator to the item
IR.Log("Pressed: " + this.Name);
IR.Log(this.Name + " Value: " + this.Value);
}
// creation of listeners for all array items
function RegisterButton()
{
for(var i = 0; i < gRegisters.length; i++)
{
var item = gRegisters[i].item;
IR.AddListener(IR.EVENT_ITEM_PRESS, item, OnPress, item);
}
}
// the function which is executed at launch
function Start()
{
RegisterButton();
}
// begin creating listeners
IR.AddListener(IR.EVENT_START,0, Start);To get access to the data of a graphic item inside the OnPress function, it is necessary to refer to it using the link this. For example:function OnPress() {
var NameOfItem = this.Name;
IR.Log( NameOfItem );
}The possibility of reference to the data is achieved by sending the 4th parameter in the AddListener method:
IR.AddListener(IR.EVENT_ITEM_PRESS, item, OnPress, item);
You can learn the name of each item pressed or subscribe for pressings on all items in the project using the following instructions.
Customer support service by UserEcho