How can I detect OK/Cancel button ?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
blies
Posts: 14
Joined: May 8th, 2007, 8:19 am

Hi everybody.
Maybe my question have a simple answer, but I don't know how to detect an Ok/Cancel button press.

I create a dialog in this way

Code: Select all

res =
"dialog { alignChildren: 'fill', text: 'xxxxx', \
...
buttons: Group { orientation: 'row', alignment: 'right', \
okBtn: Button { text:'OK', properties:{name:'ok'} }, \
cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } \
} \
}";
win = new Window (res);
win.center(); win.show();
(I omit the other fields) .. and next ? :(

Thanks in advance ;)
Image
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

You just need to set up a function to handle the click and then link the button to it like this:


function okClick(){
(your function here)
}
.
.
.
.
win = new Window (res);
win.buttons.okBtn.onClick = okClick;


Dan
blies
Posts: 14
Joined: May 8th, 2007, 8:19 am

Great! Great! Great!
Thanks! Thanks! Thanks!
Image
blies
Posts: 14
Joined: May 8th, 2007, 8:19 am

Dan, sorry for the new question.
Obviously when I call okClick, inside the function I loose every var/obj that I create before, right ?

How can I pass that parameters ?

I tried
win.buttons.okBtn.onClick = okClick(myComp,win);
.. but I got undefined errors

Why ?
Image
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

You can create variables and objects that are outside the scope of all functions and you can access those anywhere. Other than that, you can use "this" and "parent" to get at attributes of the panel objects. In your case,

"this" references the button

this.parent references the buttons group

this.parent.parent references the dialog

Dan
blies
Posts: 14
Joined: May 8th, 2007, 8:19 am

Ok .. and I don't know why I loose myComp that is set at the begin of the script :(
Image
Post Reply