Macromedia flex 2 Manual

Page of 254
162
Creating Advanced Visual Components in ActionScript
}
}
Implementing the measure() method
The 
measure()
 method sets the default component size, in pixels, and optionally sets the 
component’s default minimum size. 
Flex schedules a call to the 
measure()
 method when a call to the 
invalidateSize()
 method 
occurs. The 
measure()
 method executes during the next 
render
 event after a call to the 
invalidateSize()
 method. When you use the 
addChild()
 method to add a component to 
a container, Flex automatically calls the 
invalidateSize()
 method. 
When you set a specific height and width of a component, Flex does not call the 
measure()
 
method, even if you explicitly call the 
invalidateSize()
 method. That is, Flex only calls the 
measure()
 method if the 
explicitWidth
 property or the 
explicitHeight
 property of the 
component is NaN. 
In the following example, because you explicitly set the size of the Button control, Flex does 
not call the 
Button.measure()
 method: 
<mx:Button height="10" width="10"/>
In a subclass of an existing component, you might implement the 
measure()
 method only if 
you are performing an action that requires modification to the default sizing rules defined in 
the superclass. Therefore, to set a new default size, or perform calculations at run time to 
determine component sizing rules, implement the 
measure()
 method. 
You set the following properties in the 
measure()
 method to specify the default size: 
The 
measure()
 method only sets the default size of the component. In the 
updateDisplayList()
 method, the parent container of the component passes to it its actual 
size, which may be different than the default size. 
Properties
Characteristics Description
measuredHeight
measuredWidth
Default height 
and width
Specifies the default height and width of the 
component, in pixels. 
These properties are set to 0 until the measure() 
method executes. Although you can leave them set 
to 0, it makes the component invisible by default. 
measuredMinHeight
measuredMinWidth 
Default minimum 
height and width
Specifies the default minimum height and minimum 
width of the component, in pixels. Flex cannot set 
the size of a component smaller than its specified 
minimum size.