Home   Help Search Login Register  

Author Topic: CtrlAddEventHandler [SOLVED]  (Read 2556 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
CtrlAddEventHandler [SOLVED]
« on: 24 Oct 2009, 06:29:48 »
Hello, I have this function here:
Code: [Select]
CLM_DlgCtrl =
{
_dialog = _this select 0;
_dlgIDD = _this select 1;
_code = _this select 2;
_codeArray = _this select 3;

_ok = createDialog _dialog;

if (!_code) exitWith {};

{
((findDisplay _dlgIDD) displayCtrl (_x select 0)) ctrlAddEventHandler [(_x select 1), (_x select 2)];
} foreach _codeArray;

nil;
};


In which I am calling with:
Code: [Select]
[
"clm_dlgBank",
202,
true,
[
[
303,
"ButtonDown",
"hint 'Close Button Clicked'"
]
]
] spawn CLM_DlgCtrl;


But I keep getting:
Code: [Select]
Error ctrlAddEventHandler: Type Number, expected control

What am I doing wrong?
« Last Edit: 25 Oct 2009, 03:47:01 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: CtrlAddEventHandler
« Reply #1 on: 24 Oct 2009, 09:07:36 »
Your code array is:
[[303, "ButtonDown", {hint "Hello"}]]

But 303 is a control number (IDC), not a control. You need to use displayCtrl command to obtain a control object from its IDC and the display of its dialog.

To get the display object you may use findDisplay command passing the IDD number of your dialog.

Code: [Select]
((findDisplay DIALOGIDDHERE) displayCtrl (_x select 0)) ctrlAddEventHandler [_x select 1, call (_x select 2)];

Offline ModestNovice

  • Members
  • *
Re: CtrlAddEventHandler
« Reply #2 on: 24 Oct 2009, 22:12:49 »
Works, but now I want to add the ability to add events to the main IDD.

this throws no error, but doenst hint when I open the dialog:

DO NOT USE
Code: [Select]
CLM_DlgCtrl =
{
_dialog = _this select 0;
_dlgIDD = _this select 1;
_code = _this select 2;
_codeArray = _this select 3;

_ok = createDialog _dialog;

if (!_code) exitWith {};

{
if (_x select 0) then
{
(findDisplay _dlgIDD) displayAddEventHandler [(_x select 2), (_x select 3)];
}
else
{
((findDisplay _dlgIDD) displayCtrl (_x select 1)) ctrlAddEventHandler [(_x select 2), (_x select 3)];
};
} foreach _codeArray;

nil;
};

Calls With:
Code: [Select]
[
"clm_dlgBank",
202,
true,
[
[
true,
202,
"OnLoad",
"hint 'DIALOG OPEN'"
],
[
false,
303,
"ButtonDown",
"hint 'CLOSE BUTTON'"
]
]
] spawn CLM_DlgCtrl;


« Last Edit: 25 Oct 2009, 03:32:36 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: CtrlAddEventHandler [SOLVED]
« Reply #3 on: 24 Oct 2009, 23:15:43 »
You are adding an "OnLoad" EH after the dialog has been already created and loaded, so it will have no effect.

Define the onLoad EH in the description.ext, inside your dialog class:
Code: [Select]
   onLoad = "hint 'DIALOG OPEN'";

Offline ModestNovice

  • Members
  • *
Re: CtrlAddEventHandler [SOLVED]
« Reply #4 on: 25 Oct 2009, 03:31:27 »
ah ok, Im such a noob :(.

Thanks mate
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley