外部コードからロールアウトのローカルおよび他の項目へのアクセス

スクリプトで書かれたユーティリティやロールアウトで定義したローカル コンポーネントは、そのユーティリティやロールアウト オブジェクトのプロパティとして外部コードからのアクセスが可能です。このオブジェクトがユーティリティやロールアウト定義上で命名された新規のグローバル変数(ネストされたロールアウトの場合はローカル変数)に割り当てられます。

例:

    utility foo "Utility"
    (
      local var1, var2
      checkbox enable "Enable"
      rollout setup "Setup" -- local rollout
      (
        local var3
        button doit "Execute" enabled:false
        on doit pressed do
        (
          var3 = var1 + var2
        )
      ) --end rollout
      function frab a b = (var1 = b-a; var2 = a*b)
      on enable changed state do
      (
        frab 10 20
        if state then
        (
          addRollout setup
          setup.doit.enabled = true
        )
        else
          removeRollout setup
      ) --end on enable handler
    ) --end utility

この例では、ユーティリティを定義して、foo と命名されたグローバル変数内にユーティリティ オブジェクトを配置します。ユーティリティ内のコンポーネントには、リスナーや他のコードからオブジェクトのプロパティとしてアクセスできます。 プロパティ名としては、変数やアイテム名を使用します。プロパティ名としてイベント名を使用すると、ユーザ インタフェースにおけるすべてのイベント ハンドラ関数にも、アイテムのサブプロパティとしてアクセスできます。

例:

    -- Gets and prints foo's local variable, var1
    print foo.var1
    -- test foo's enabled checkbox state:
    if foo.enable.state then print "ON!" else print "OFF"
    -- Sets the foo's enabled checkbox state to false.
    -- This will change the checkbox, but not execute the event handler
    -- which deals with the adding/removing the local rollout
    foo.enable.state = false
    -- Calls the 'changed' handler function of the enable checkbox
    -- This will call the handler with a value of false, but will NOT
    -- change the checkbox's state itself.
    foo.enable.changed false
    -- This willbothcall the handler with a value of false
    -- AND change the checkbox's state, mimicking a checkbox change
    -- via the UI and the mouse:
    foo.enable.changed (foo.enable.state = false)
    -- Calls its 'frab' function local to the foo utility:
    foo.frab 100 200
    -- Sets foo’s setup rollout local variable, var3
    foo.setup.var3 = 42
    -- Calls the change handler function for doit button in the
    -- setup rollout of the foo utility:
    foo.setup.doit.pressed()

スクリプト ユーティリティとロールアウト ユーティリティのローカル変数、関数、構造体は、ユーティリティやロールアウトが初めて表示されるときではなく、初めて定義されるときに初期化されます。これにより、定義後は他のコードがローカル関数を使ってローカル値にアクセスできるようになります。

注:

ユーティリティまたはロールアウトを開くたびに、すべてのローカル値が再初期化され、開く前に設定された値はすべて失われてしまいます。

例:

    -- 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 -
    createDialog test 100 40
    --all variables will be reset!
    --> true
    test.testSpinner.value --get the spinner value again
    --> 50.0 --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