PDA

View Full Version : Event handler question...is it possible?


bkravi
10-20-2009, 09:43 AM
Hi,

see code below, I want to execute cbtn_B1 event handler code when I press button btn_C1, right now it just set the on off state of cbtn_B1 but do not execute any code that is associated with that button. is it possible?


rollout myRollout "R1"
(
checkbutton cbtn_B1 "CheckButton"
button btn_C1 "Button"

on cbtn_B1 changed state do ( if state then (for l in lights do l.ishidden = true) else (for l in lights do l.ishidden = false) )

on btn_C1 pressed do cbtn_B1.state = true

)
createdialog myRollout 100 100


Thanks
Ravi

SyncViewS
10-20-2009, 11:44 AM
Hi Ravi, you can take the code in the checkbutton out to a function, then call it from both buttons:

rollout myRollout "R1"
(
checkbutton cbtn_B1 "CheckButton"
button btn_C1 "Button"

function setLightVis bValue =
(
if (bValue == true) then
(
for l in lights do
l.ishidden = true
)
else
(
for l in lights do
l.ishidden = false
)
)

on cbtn_B1 changed bState do
(
setLightVis bState
)

on btn_C1 pressed do
(
setLightVis true
cbtn_B1.state = true
)
)

createdialog myRollout 100 100
- Enrico

Bobo
10-20-2009, 01:51 PM
on btn_C1 pressed do cbtn_B1.changed (cbtn_B1.state = true)



The event handler is a function of the control, so you can call it.
Since it expects one argument containing the new state, we pass the new TRUE value as the argument, while at the same time setting the state of the button to the same value.

bkravi
10-21-2009, 07:12 PM
Thanks Bobo it works!

CGTalk Moderation
10-21-2009, 07:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.