3.8 User-defined Event
You can use user-defined events as well as Touch events defined on the object .
By transmitting information by user-defined events in Form and Dialog , etc., the coupling between Form and Dialog becomes looser, and development efficiency and debugging efficiency are improved.
The following is an example of issuing a simple user-defined event.
Issuing a simple user event
Function OnTouch (e) {
::
PostEvent (new Event (UserEvent + 1, "CodeSelect"));
::
}
UserEvent + 1 is the event number and “CodeSelect” is the event name. Numbers smaller than the event number defined in UserEvent cannot be used in user events because they are reserved by the system.
If you don’t use the event number, you can write:
Issuing a simple user event
Function OnTouch (e) {
::
PostEvent (new Event ("CodeSelect"));
::
}
In this format, the argument of the “CodeSelect” part must always describe a string constant.
The above event can be caught by the following event handler.
Function OnCodeSelect (e) {
::
}
To define the data that accompanies the event:
Issuing user events with data
Function OnTouch (e) {
::
var userEvent1 = new Event (UserEvent + 1, "CodeSelect") {
String data1;
String data2;
}
userEvent1.data1 = "abc";
userEvent1.data2 = "123";
PostEvent (userEvent1);
::
}
The above event can be caught by the following event handler.
Function OnCodeSelect (e) {
if (e.data1 == "abc") {
::
}
::
}