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 access local values at any time after definition.

Note: Whenever a utility or rollout is opened, all local values will be reinitialized and any values set before opening will be lost!

For Example:

--define a test rollout with a spinner UI element

--initialized to value of 50.0 and two local variables:

rollout test "Test"

(

local testValue1

local testValue2 = 10

spinner testSpinner "Spinner" range:[0.0,100.0,50.0]

)

Rollout:test

test.testSpinner.value --peek into the spinner's value

50.0 --it is 50 as expected

test.testValue1 --get the first local variable's value

undefined --it is set implicitly to undefined

test.testValue2 --get the other local variable's value

10 --it is set to 10 as expected

test.testSpinner.value = 60.0 --change the spinner's value to 60.0

60.0

test.testSpinner.value --get the value back to see if it worked

60.0

test.testValue1 = 20 --set the first local's value to 20

20

test.testValue1 --get the first local's value

20 --now it is initialized to 20

test.testValue2 = 40 --set the second local's value to 40

40

test.testValue2 --get the second local's value

40 --now it is 40

--now create a dialog with the rollout -

--all variables will be reset!

createDialog test 100 40

true

test.testSpinner.value --get the spinner value again

  1. --it is back to the default value of 50.0

test.testValue1 --get the first local's value again

undefined --it is back to undefined

test.testValue2 --get the second local's value again

10 --it is back to 10