Top-Level Entities
There are three kinds of top-level entity in a script object—properties, handlers, and script objects (see Chapter 7 and Chapter 8 for script properties and handlers).
Accessing Top-Level Entities
Outside a script object, its top-level entities are accessible on demand to any code that can see the script object. This means that they can be both fetched and set by such code.
The syntax is as follows:
Use the
ofoperator (or the apostrophe-ess operator) to specify the top-level entity in relation to its script object. For example:script myScript property x : "Howdy" on sayHowdy( ) display dialog x end sayHowdy script innerScript display dialog x end script end script set x of myScript to "Hello" myScript's sayHowdy( ) -- Hello run innerScript of myScript -- HelloAlternatively, refer to the top-level entity within a tell block addressed to the script object. This requires the use of the keyword
its, except in the case of a handler call. For example:script myScript property x : "Howdy" on sayHowdy( ) display dialog x end sayHowdy script innerScript display dialog x end script end script tell myScript set its x to "Hello" sayHowdy( ) run its innerScript end tell
In that last example, if you omit the keyword its
from the line where you set x, you set an implicit
global x, not the property of
myScript. If you omit the keyword
its from the line where you run
innerScript, there is a runtime error, because no
innerScript is in scope.
(It makes no difference whether or ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access