Newbie Question: Script Objects
Newbie Question: Script Objects
- Subject: Newbie Question: Script Objects
- From: Simon Brown <email@hidden>
- Date: Sun, 16 Feb 2003 17:17:55 +0000
Hello,
I'd like to know if my assumption that properties declared at the root level
of script objects persist only as long as the parent script app is running
and will be reset next time the whole script is executed (if not, there's no
point in me trying to use a script object for what I'm trying to achieve).
I would also like to know why only one of the following scripts works,
dependent on the position of the script object in the script:
Script 1: This works
(* This version DOES work, seemingly because the myHandlers script object
is ABOVE the non-'Run' handler - anotherHandler() - that calls it *)
property x : 0
--NB Script object at TOP of script
script myHandlers
on increment()
set x to x + 1
display dialog "Count is now " & x & "."
end increment
end script
on run
tell myHandlers to increment() --this call works OK in both versions
log "Run Handler called the Script Object, x is now " & x
anotherHandler()
end run
on anotherHandler()
tell myHandlers to increment()
log "AnotherHandler called the Script Object, x is now = " & x
end anotherHandler
Script 2: This doesn't work
(* This version doesn't work, seemingly because the myHandlers script object
is BELOW the non-'Run' handler - anotherHandler() - that calls it *)
property x : 0
on run
tell myHandlers to increment() --this call works OK in both versions
log "Run Handler called the Script Object, x is now " & x
anotherHandler()
end run
on anotherHandler()
(* Next line errors - "The variable myHandlers is not defined" *)
tell myHandlers to increment()
log "AnotherHandler called the Script Object, x is now = " & x
end anotherHandler
(* NB Script object at BOTTOM of script *)
script myHandlers
on increment()
set x to x + 1
display dialog "Count is now " & x & "."
end increment
end script
TIA for whatever you can tell me to improve my understanding of this issue.
--
Simon
--------------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.