ボタンと進行状況バーを備えた UI を作成しました。進行状況バーは、実際には、使用状況を示す小さなカラー インジケータとして使用されています。見つかったファイルに応じて進行状況バーの色を変更したいと考えています。
ところが、進行状況バーを含んだロールアウトを作成した後に配色しても、「undefined」と表示されてしまいます。進行状況バーを作成した後でも、収集したデータに基づいて、その進行状況バーの色を変更する必要があります。
何らかの進行状況バーを含んだ UI ロールアウトを作成しているとします。
macroScript TestUI category:"MXS Help" ( -- note that the mactoscript itself defines a scope rollout testUI_Rollout"Testing..." ( progressbar Indicator01 width:20 height:20 color:green value:100 ) createDialog testUI_Rollout 100 100 )
Indicator01 にアクセスするには次の 3 つの方法があります。
ロールアウト内部
ロールアウトの作成前
ロールアウトの作成後
1 つ目の方法は明白であり、ここでは説明しません。
2 つ目の方法方法は、まだ定義されていないが、少なくとも事前に初期化された値にアクセスできるので興味深い点があります。
macroScript TestUI category:"MXS Help" ( local testUI_Rollout -- this defines a variable -- which has a memory address but still not valid value. -- If you create a function that accesses the variable, the -- evaluation will proceed as it sees the variable and assumes -- it is a valid rollout. Later, when the actual execution of -- the script happens, the variable will REALLY point at a valid -- rollout, so everybody is happy! fn changeTheLamp theColor = ( testUI_Rollout.Indicator01.color = theColor -- the function is outside of the rollout context, -- so it has to prefix the UI element access. ) -- This rollout is defined even before the rollout with the lamp -- Still, it will be able to change the lamp to yellow using the -- above function! rollout Changer_Rollout"Testing..." ( button changeIt"CHANGE STATE" on changeIt pressed do changeTheLamp [255,255,0] ) rollout testUI_Rollout"Testing..." ( progressbar Indicator01 width:20 height:20 color:green value:100 ) createDialog Changer_Rollout 100 30 100 100 createDialog testUI_Rollout 100 100 100 200 )
3 番目の方法では、ダイアログ ボックスを作成した後に、Indicator01 の値にアクセスするか、その色を変更する必要があるとします。この場合、変数 TestUi_Rollout がロールアウト定義を示しているので、Indicator01 にアクセスするには、次のようにこのロールアウト名を Indicator01 の前に記述する必要があります。
macroScript TestUI category:"MXS Help" ( -- note that the mactoscript itself defines a scope rollout testUI_Rollout "Testing..." ( progressbar Indicator01 width:20 height:20 color:green value:100 ) createDialog testUI_Rollout 100 100 TestUI_rollout.Indicator01.color = red )
この行は、TestUI_rollout が見えているマクロ スクリプトのスコープ内部に記述されています。このロールアウトに別のスクリプトからアクセスする場合は、このロールアウトをグローバル変数として定義する必要があります。
macroScript TestUI category:"MXS Help" ( global testUI_Rollout --now the rollout is visible to anyone outside! rollouttestUI_Rollout"Testing..." ( progressbar Indicator01 width:20 height:20 color:green value:100 ) createDialog testUI_Rollout 100 100 ) macroScript ChangeStatusTestUI category:"MXS Help" ( TestUI_rollout.Indicator01.color = red )
最初のマクロを実行すると、緑のライトを備えたロールアウトが表示されます。
2 番目のマクロを実行すると、ライトが赤に変わります。
ご覧のように、それぞれのロールアウトを、見えるように上位のスコープでローカルまたはグローバル変数として定義していれば、どこからでもすべてのロールアウトにアクセスできます。さらに便利なことには、実際の内容を定義する前に変数を宣言でき、定義される時点よりも前の時点でそれらにアクセスすることができます。