Dynamic Image re-size in proportional ratio in flash AS3


Dynamic resize image in flash

var ratio:Number;//ratio
ratio = movieClip.height/movieClip.width;//calculation ratio


With a if loop we check the width of the image is bigger than the
maximum width we want, if it is, then we set the width to the
maximum value and re-calculate the height proportional.

if (movieClip.width>maxWidth) {
movieClip.width = maxWidth;
movieClip.height = Math.round(movieClip.width*ratio);
}

After the height is updated we check if it is bigger than the
maxHeight we want, if it is, then we set the height to the maximum
value and re-calculate the width proportional.

if (movieClip.height>maxHeight) {
movieClip.height = maxHeight;
movieClip.width = Math.round(movieClip.height/ratio);
}
Advertisements

5 thoughts on “Dynamic Image re-size in proportional ratio in flash AS3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s