width property
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
double get width {
return getBounds($parent, _sHelperRect)!.width;
}
Sets the width of the object to the given value
.
If the given value is null or NaN, an error is thrown.
If the object has a zero scale, it is first set to 1.0 before computing
the new scale based on the new width value.
Otherwise, the current scale is used to compute the current actual width
of the object, which is then used to
determine the new scale based on the new width value.
The value
parameter should be the desired new width value of the object.
Implementation
set width(double? value) {
if (value?.isNaN ?? true) {
throw '[$this.width] can not be NaN nor null';
}
double? actualW;
var zeroScale = _scaleX < 1e-8 && _scaleX > -1e-8;
if (zeroScale) {
scaleX = 1.0;
actualW = width;
} else {
actualW = (width / _scaleX).abs();
}
scaleX = value! / actualW;
}