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);

Share and Enjoy

  • Facebook
  • Twitter
  • Google Plus
  • Live
  • Delicious
  • Digg
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • Instapaper
  • FriendFeed


  1. I really appreciate Mr Chandan to develop codinghint.com.
    people can use it for coding hint and you can share your ideas also.

  2. Spot on with this write-up, I really assume this website needs much more consideration. I’ll most likely be once more to read much more, thanks for that info.