Flash AS3 Function: Scale and Resize a MovieClip in Proportion

Leave a comment Standard

One of the things that drives me nuts is when you have to scale or resize a movie clip and keep it in proportion at the same time. So I created this function to do all the heavy lifting, all you have to do is pass it the movie clip and give it the max dimension size and it does all the rest of the hard work.

function resize(mc:MovieClip, maxDimension:int):MovieClip
{
            //already under the maxDimension
            if (mc.width <= maxDimension && mc.width <= maxDimension)
                return mc;
            else
            {
                var divisor = ( mc.width >= mc.height) ? mc.width / maxDimension : mc.height / maxDimension;
                mc.width = Math.floor(mc.width / divisor);
                mc.height = Math.floor(mc.height / divisor);
            }

	return mc;
}
Advertisements

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