Hi,
Edit: I just realized that I should say “Handlers” instead of “Functions”. (Old habits, you know.)
I’ve built a multi-script application. A couple of functions are used in one or more other scripts. Currently I copy the functions in every script as I can’t get the “load script” function to work.
(Please note that I’ve tried to read every post about this subject. Hence the several ways of trying to achieve this)
I built a Functions.applescript. Inside this applescript, I have (for example)
on FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg)
tell window "ProgressWindow"
center
show
set title to titlebarmsg
tell text field "TopMsg" to set content to topmsg
tell text field "BottomMsg" to set content to bottommsg
activate
tell progress indicator "BarberPole"
-- This makes the application use a separate thread to handle the animation
set uses threaded animation to true
set indeterminate to true
set visible to true
start
end tell
end tell
end FUNC_Initialize_BP_PGB
----------------------------------------------------------------
----------------------------------------------------------------
on FUNC_quit_BP_PGB()
tell window "ProgressWindow"
tell progress indicator "BarberPole"
stop
end tell
hide
end tell
end FUNC_quit_BP_PGB
..
more functions
..
These functions work fine as long as I use a separate copy in each applescript.
However, to use this Functions script as a reusable functions library (as I’m used to in other languages) I tried in my other scripts, that use these common functions, to:
on will finish launching theObject
global mYFunctions -- Needed to set this one otherwise I got an "unknown variable" error
set mYFunctions to load script (path to resource "Functions.scpt" in directory "Scripts")
set FUNC_Initialize_BP_PGB to FUNC_Initialize_BP_PGB()
set FUNC_quit_BP_PGB to FUNC_quit_BP_PGB()
... some more functions ...
end will finish launching
In the other scripts I tried then all kind of options like:
FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg) -- direct call based on reference
tell mYFunctions to FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg)
mYFunctions's FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg)
None of them works and throws an error in my face during startup.
What am I doing wrong?