width property

  1. @override
double width
override

Indicates the width of the display object, in dp. The width is calculated based on the bounds of the content of the display object. When you set the width 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.scaleX) // 1;
  rect.width = 200;
  trace(rect.scaleX) // 2;

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

Implementation

@override
double get width {
  throw 'Use `stage.stageWidth` instead.';
}
  1. @override
void width=(double? value)
override

The width setter is overridden to throw an error since the stage's height is defined by the size of the canvas and cannot be changed directly.

Implementation

@override
set width(double? value) {
  throw 'Cannot set width of stage';
}