56
Chapter 3: Creating Advanced Components in Flash MX 2004
Flex only calls the
commitProperties()
method after it calls the
invalidateProperties()
method.
For example, the ViewStack container uses the
commitProperties()
method to maximize
performance. When you set the
ViewStack.selectedIndex
property, the ViewStack container
doesn’t update to a new page right away. Instead, it privately stores a
pendingSelectedIndex
property. When it is time for Flash Player to update the screen, Flex calls the
commitProperties()
,
measure()
,
layoutChildren()
, and
draw()
methods. In the
commitProperties()
method, the ViewStack container checks to see whether the
pendingSelectedIndex
property is set, and it updates the selected index at that time.
The motivation to use the
commitProperties()
method is to delay processing until the last
minute, so that Flash Player avoids doing computationally expensive, redundant work. For
example, if a script changes the
ViewStack.selectedIndex
property 15 times, you would want
to minimize the number of times the display of the ViewStack container updates when the
selectedIndex
property changes. By using the
commitProperties()
method, you can update
the
pendingSelectedIndex
property 15 times, and then only do the rendering once.
This is most useful for properties that are computationally expensive to update. If setting a
property is inexpensive, you can avoid using the
commitProperties()
method.
Implementing the measure() method
Generally, the
measure()
method is only called once when the component is instantiated. The
component’s container sets the initial size and Flex calculates the preferred minimum and
maximum sizes. You can use the
measure()
method to explicitly set the size of the component,
although Macromedia does not recommend doing this when developing components.
You can set the following properties in the
measure()
method. Flex calculates them, but you can
override them:
•
_measuredMinWidth
•
_measuredMaxWidth
•
_measuredMinHeight
•
_measuredMaxHeight
•
_measuredWidthFlex
•
_measuredHeightFlex
•
_measuredPreferredWidth
•
_measuredPreferredHeight
The Flex properties (those that end with the word Flex) define limits for when the object is
resized. These
measured
properties are used for layout in containers if your component doesn’t
explicitly set a
preferredWidth
or
preferredHeight
attribute.
Controls calculate the values of these based on runtime properties. For example, the Button
control’s
measure()
method examines how wide its label is in order to compute the value of the
_measuredPreferredWidth
property.
Содержание FLEX - DEVELOPING COMPONENTS AND THEMES
Страница 1: ...Developing Flex Components and Themes in Flash Authoring ...
Страница 4: ...4 Contents ...
Страница 44: ...44 Chapter 2 Creating Basic Components in Flash MX 2004 ...
Страница 82: ...82 Index ...