1
votes

I have this Bitmap defined like so:

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

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

What I am trying to do is set the height and have the width be proportional to height. I tried googling my issue, but all I saw was how to scale the bitmap image. It has been a really long time since I did ActionScript 3 and I cant seem to figure this one out. Please Help.

1

1 Answers

3
votes

In AS3 you can use a display object's scaleX & scaleY properties to maintain the native aspect ratio.

Here is a common way to proportionally scale an item:

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

The scale properties are essentially just alternative to width/height in relative terms - 1 being native size, 2 being double the size, 0.5 being half etc...