I’ve been struggling to figure out the best way to work with the Check Box and decided to turn here.
All I’m really trying to do is get the value (checked or unchecked) of the box. Then execute different functions depending on the result of the check box. (yes, very simple I know)
to test, I made a simple program with a check box and 3 buttons.
button 1 will get the true or false value of my property check box and log it to the console
button 2 will set the value of check box to false and will in turn deselect the box
button 3 will set the value of check box to true and will in turn check the box
the issue is when I manually click the check box and then look to get it’s status, it won’t reflect the changes.
Ive used bindings to connect the check box to my property checkbox
heres the code:
script checkItAppDelegate
property parent : class "NSObject"
property CheckBox : missing value
on applicationWillFinishLaunching_(aNotification)
set CheckBox to false
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on ClickIt_(sender)
set my CheckBox to true
-- CheckBox's setState_(true)
end ClickIt_
on GetStatus_(sender)
if my CheckBox is true then
log "its true "
end if
if my CheckBox is false then
log "its false"
end if
end GetStatus_
on UnClickIt_(sender)
--CheckBox's setValue_(false)
set my CheckBox to false
end UnClickIt_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
I had to use the set my checkbox to false rather than the CheckBox’s setValue_(false) because the latter wasnt working for some reason.
Hi fortie04
i have been using this style to get and set check box values, see how it goes for you
script get_and_set_check_boxAppDelegate
property parent : class "NSObject"
property checkboxinfo : missing value
on CreateInfo_(sender)
checkboxinfo's intValue() --return 1 or 0
display dialog result
checkboxinfo's setIntValue_([1]) --set check box to 1 or 0
display dialog result
end CreateInfo_
This is partly working for me.
I think it’s required to set the initial value to 0 during the “applicationWillFinishLaunching”
If I just get the value of the box before I check/uncheck the box it won’t return an intValue at all.
What is the difference between setting the intValue to 1 or 0 with cocoa ( chcekbox’s setIntValue_(0))
or just setting it with AS: set my checkbox to 1 or 0
If I was to use the setState property would I no longer need bindings?
It seems like bindings are the best way to go because it will update immediately with the lease amount of code.
Should I pass setState a true/false argument or a 1/0 argument?
Also, It seems that a check box can be: True, False or Void.
What is the difference between false and void?
Shane, I’ve been using your coming to florida program to learn about bindings and the checkbox.
why do you not do:
set my newAlumni to false -- sets it to a boolean
Why is ASOC do you need to identify properties as “my”?