Accessing Locals and Other Items in a Rollout from External Code

The local components defined in a scripted utility or rollout are accessible to external code as properties of the utility or rollout object. Recall that the rollout object is assigned to a new global variable (or local variable if a nested rollout) named on the utility or rollout definition.

Example:

utility foo "Object Frabulator"

(

local var1, var2, ...

...

checkbox enable "Enable frabber"

...

rollout setup "Setup frabber" -- local panel

(

local var3

button doit "Execute"

...

on doit pressed do ...

)

function frab a b = ...

...

on enable changed state do ...

...

)

The example defines the utility and places the utility object in a global variable named foo. You can access components in the utility from the Listener or other code as properties of that object, using the name of the variable or item as the property name. Any event-handler functions supplied for user-interface items can also be accessed as sub-properties of the item, using the event name as the property name. For example:

print foo.var1            -- get foo's local variable, var1

if foo.enable then ...    -- test foo's enabled checkbox

foo.enable = false        -- set it

foo.enable.changed false  -- call its 'changed' handler function

foo.frab $box01 $box02    -- call its 'frab' function

foo.setup.var3=10         -- set foo's setup rollout local variable, var3

foo.setup.doit.pressed()  -- call 'changed' handler function for doit button in setup rollout

The local variables, functions, and structures in scripted utilities and rollouts are initialized as soon as the utility or rollout is first defined, rather than when the utility or rollout is first displayed. This allows other code to use local functions and set local values at any time after definition.