I’m an AS Studio novice trying to get a simple interface to work without success. The interface contains several radio button matrices, each with two or three buttons. I’m trying to disable a certain button if a button of another matrix is clicked. Specifically, I’m trying to disable the “True” button of the “Borderless Margins” matrix if the “US Legal” button of the “Paper Size” matrix is clicked. I keep getting a “NSReceiverEvaluationScriptError: 3 (1)” error when the “set” statement tries to execute. Interestingly, if the “set” statement precedes the “if” statement, I don’t get the error. I’d be very grateful for any help with this frustrating problem.
on clicked theObject
tell (window of theObject)
if (name of theObject is "US Legal") and (name of control view of theObject is "Paper Size") then
set enabled of cell "True" of matrix "Borderless Margins" to false
end if
end tell
end clicked
probably it is a address error.
you have a tell block (window of theObject) and then you address theObject,
which already contains the reference to the window.
Maybe this works:
on clicked theObject
if (name of theObject is "US Legal") and (name of control view of theObject is "Paper Size") then
set enabled of cell "True" of matrix "Borderless Margins" of (window of theObject) to false
end if
end clicked
Thank you for the insight about the referencing conflicts. Strangely, I still get the “NSReceiverEvaluationScriptError: 3 (1)” error when I execute your code. But I just discovered that if I replace (window of theObject) with window “Main” (which is the name of the window), the code works without the error:
on clicked theObject
if (name of theObject is "US Legal") and (name of control view of theObject is "Paper Size") then
set enabled of cell "True" of matrix "Borderless Margins" of window "Main" to false
end if
end clicked
Because I am trying to learn the language, I would love to hear your ideas as to why (window of theObject) does not work. It might save me many hours of frustration in the future!
Can I please trouble you for advice on one other very strange problem that has arisen now that I’ve gotten the above code to work? Once I’ve clicked the “US Legal” button, if I then click the button to the right of it in the same “Paper Size” matrix (it’s a horizontal row of buttons), the “US Legal” title completely disappears from the display!!! I’m sure it’s something very simple (and dumb) that I’m doing, but I just can figure it out!
It’s quite difficult to speak about details with just a little code snippet,
but generally you always should care about the hierarchy of the reference(s)
in the on clicked handler, for example, theObject contains the full reference.
If the clicked object is part of a box or a text view, then there is no superior element window
and the script fails
Maybe you have somewhere a set visible of whatEver to false line.
Use the log option to get values displayed in Xcode’s log window
just add a line like:
log (enabled of cell "True" of matrix "Borderless Margins" of window "Main") as string
and you see always the value when the script passes the line
I just discovered how to correct the disappearing title problem. I turned on the “Background” → “Draw” attribute (ie, checked the “Draw” box) for each of the radio button matrices, and voila, the titles don’t disappear when I click buttons! I presume this causes the window to redraw its background after a button click, but that’s obviously just a guess. Does that make any sense? In any case, thank you very much for helping me through this.