height property

double height

Indicates the height of the display object, in dp. The height is calculated based on the bounds of the content of the display object. When you set the height property, the scaleX property is adjusted accordingly, as shown in the following code:

  var rect:Shape = new Shape();
  rect.graphics.beginFill(0xFF0000);
  rect.graphics.drawRect(0, 0, 100, 100);
  trace(rect.scaleY) // 1;
  rect.height = 200;
  trace(rect.scaleY) // 2;

A display object with no content (such as an empty sprite) has a height of 0, even if you try to set height to a different value.

Implementation

double get height {
  return getBounds($parent, _sHelperRect)!.height;
}
void height=(double? value)

Sets the height of this display object to the specified value.

If the given value is null or NaN, an exception is thrown. If the display object's scale on the Y-axis is zero or very close to zero, it is reset to 1.0 in order to properly calculate the actual height. The actual height is then calculated based on the current width and scale of the display object. Finally, the scale on the Y-axis is set so that the actual height matches the specified value.

If you need to retrieve the height of the display object, use the height getter instead.

Throws an exception if the given value is null or NaN.

Implementation

set height(double? value) {
  if (value?.isNaN ?? true) throw '[$this.height] can not be NaN nor null';
  double? actualH;
  var zeroScale = _scaleY < 1e-8 && _scaleY > -1e-8;
  if (zeroScale) {
    scaleY = 1.0;
    actualH = height;
  } else {
    actualH = (height / _scaleY).abs();
  }
  scaleY = value! / actualH;
}