ActionScript 3 位图宽度与高度成比例

ActionScript 3 Bitmap width proportional to height

我有这样定义的位图:

[Embed(source="images/floorplan.png")]
var Floorplan:Class;

var floorplanImg:Bitmap = new Floorplan();
floorplanImg.y = 510;
floorplanImg.x = 40;
floorplanImg.height = 890;

我想做的是设置高度并使宽度与高度成正比。我试着用谷歌搜索我的问题,但我所看到的只是如何缩放位图图像。自从我使用 ActionScript 3 以来已经有很长时间了,我似乎无法弄清楚这一点。请帮助。

在 AS3 中,您可以使用显示对象的 scaleXscaleY 属性来保持原始纵横比。

这是按比例缩放项目的常用方法:

floorplanImg.height = 890; //when you change the height, it automatically changes the scaleY to the relative amount from the original (1)
floorplanImg.scaleX = floorplanImg.scaleY; //make the scaleX the same as the new scaleY to keep the aspect ratio the same

缩放属性本质上只是相对于 width/height 的替代 - 1 是原始大小,2 是两倍大小,0.5 是一半等。 ..