I built a screen with a set of sliders in it. There is one standard box around it and inside two smaller boxes for common options and Advanced options.
I also have a button “Set values to defaults”. This calls a function to reset the slider values (sounds logical, doesn’t it?)
I first wanted to tested it with the reset of one slider value instead of resetting them all, so my coding started small for only one slider.
I’ve used the option
tell slider "BL" of window "MainWindow"
set newvalue to its contents
set its contents to BlendLevel
end tell
where BlendLevel is a global.
I also tried
set content of slider "BL" of window "MainWindow" to BlendLevel
Both options give me:
I also tried (being desperate) to
set content of slider "BL" of box "Options" of box "Common_Options" of window "MainWindow" to BlendLevel
but this gives me “unknown variables” errors for the boxes, which I can understand, but as mentioned: I was by now desperate.
Note: The on action event works fine. If slider values change I can read and use them, but I also want to reset them.
Sorry but I don’t understand what you mean. I did a quick BBS, manual and google search on direct element but I can’t find anything.
Can you explain it please?
slider x of box "standard box around" of window "MainWindow"
You have to find out the reference from the root object (MainWindow) to the slider.
But if the slider is connected to a AppleScript handler like on actiontheObject, then theObject contains the reference.
I usually define properties for all frequently used objects like
property mySlider : ""
on awake from nib theObject
set mySlider to a reference to slider "mySlider" of box "myBox" of window "main"
end awake from nib
set content of slider "BL" of box "Options" of box "Common_Options" of window "MainWindow" to BlendLevel
However in my REAL code it said:
set content of slider "BL" of box Options of box Common_Options of window "MainWindow" to BlendLevel
And that’s off course why it gave the “unknown variables” errors for the boxes as the names were not quoted. I have been looking at this line for I don’t know how many times to check on typo’s or incorrect references but I didn’t spot the quotes.
Now it works!
Sorry for wasting your time. Thanks for helping me.
Thanks also for the tip on the reference. That’s a nice one too.