Language Guide
CHAPTER 9
Script Objects
270 Initializing Script Objects
script object. For example, the makePoint handler in the following script
contains a script object definition for the script object point:
on makePoint(x, y)
script point
property xCoordinate:x
property yCoordinate:y
end script
return point
end makePoint
set myPoint to makePoint(10,20)
get xCoordinate of myPoint
get yCoordinate of myPoint
AppleScript initializes the script object point when it executes the makePoint
command. The parameter variables in the makePoint handler, in this case, x
and y, become local variables of the script object point. The initial value of x is
10, and the initial value of y is 20, because those are the parameters of the
makePoint command that initialized the script object.
One way to use script object definitions in handlers is to define constructor
functions, that is, handlers that create script objects. The following script uses
a constructor function to create three script objects.
on makePoint(x, y)
script
property xCoordinate:x
property yCoordinate:y
end script
end makePoint
set PointA to makePoint(10,20)
set PointB to makePoint(100,200)
set PointC to makePoint(1,1)
As in the previous example, you can retrieve the coordinates of the three script
objects using the Get command.