User Guide

Writing the component’s ActionScript code 11
You can set the following properties in the measure() method. Flex calculates the values of these
properties, but you can override them in the
measure() method:
_measuredMinWidth
_measuredMaxWidth
_measuredMinHeight
_measuredMaxHeight
_measuredPreferredWidth
_measuredPreferredHeight
The properties define limits for when the object is resized. These measured properties are used for
layout in containers if your component doesnt 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.
Note: Although you can let Flex determine these values for you, your application startup time will
decrease if you set them yourself.
By default, Flex sets the values of _measuredPreferredWidth and _measuredPreferredHeight
to the values of the current height and width, but you should override them. The following
example of the
measure() method from the Label component sets a default width and height if
the label text field is empty:
function measure(Void):Void {
var myTF = _getTextFormat();
var txt = text;
if (txt == undefined || txt.length < 2) {
txt = "Wj";
}
var textExt = myTF.getTextExtent2(txt);
var textW = textExt.width + 4;
var textH = textExt.height + 4;
if (textW == undefined) {
textW = 20;
}
if (textH == undefined) {
textH = 8;
}
trace("Label: " + textW + " " + textH);
_measuredPreferredWidth = textW;
_measuredPreferredHeight = textH;
}