
CHAPTER 4: User-Interface Tools ScriptUI programming model 66
The order of optional parameters must be maintained. Use the value undefined for a parameter you do
not wish to set. For example, if you want to use automatic layout to determine the bounds, but still set the
title and text in a panel and button, the following creates
Panel and Button elements with an initial text
value, but no
bounds value:
dlg.btnPnl = dlg.add(’panel’, undefined, ’Build it’);
dlg.btnPnl.testBtn = dlg.btnPnl.add(’button’, undefined, ’Test’);
TIP: This example creates a dynamic property, btnPnl, on the parent window object, which contains the
returned reference to the child control object. This is not required, but provides a useful way to access your
controls.
A new element is initially set to be visible, but is not shown unless its parent object is shown.
Creation properties
Some element types have attributes that can only be specified when the element is created. These are not
normal properties of the element, in that they cannot be changed during the element’s lifetime, and they
are only needed once. For these element types, you can supply an optional
creation-properties
argument to the
add method. This argument is an object with one or more properties that control aspects
of the element’s appearance, or special functions such as whether an edit text element is editable or Read
only. See “
Control object constructors” on page 123 for details.
You can also specify the creation properties for new objects using the resource specification format; for
details, see “
Resource specifications” on page 78.
All user-interface elements have an optional creation property called
name, which assigns a name for
identifying that element. For example, the following creates a new
Button element with the name ok:
dlg.btnPnl.buildBtn = dlg.btnPnl.add(‘button’, undefined, ‘Build’, {name:’ok’});
NOTE: In Photoshop CS, panel coordinates were measured from outside the frame (including the title bar),
but in Photoshop CS2, panel coordinates are measured from the inside the frame (the content area). This
means that if you use the same values to set the vertical positions of child controls in a panel, the positions
are slightly different in the two versions. When you add a panel to a window, you can choose to set a
creation property (
su1PanelCoordinates), which causes that panel to automatically adjust the positions
of its children; see the
add method for panel. When automatic adjustment is enabled, you provide
position values that were correct for Photoshop CS, and the result is the same in Photoshop CS2, CS3, CS4,
or CS5. You can also set automatic adjustment for a window; in this case, it applies to all child panels of that
window unless it is explicitly disabled in the child panel. See
Window object constructor.
Accessing child elements
A reference to each element added to a container is appended to the container’s children property. You
can access the child elements through this array, using a 0-based index. For controls that are not
containers, the
children collection is empty.
In this example, the
msgPnl panel was the first element created in dlg, so the script can access the panel
object at index 0 of the parent’s
children property to set the text for the title:
var dlg = new Window('dialog', 'Alert Box Builder');
dlg.msgPnl = dlg.add('panel');
dlg.children[0].text = 'Messages';
Kommentare zu diesen Handbüchern