﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Keith Hair &#187; Constrain Proportion</title>
	<atom:link href="http://keith-hair.net/blog/tag/constrain-proportion/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Mon, 17 May 2010 16:02:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Resizing width and height proportionately</title>
		<link>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/</link>
		<comments>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 06:06:36 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Constrain Proportion]]></category>
		<category><![CDATA[Porportional]]></category>
		<category><![CDATA[Resize]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=25</guid>
		<description><![CDATA[If you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus. I like to have this same ability when I'm writing ActionScript to resize objects proportionately too. Here I use the functions to set the sizes so when I set width, height is changed accordingly. The [...]]]></description>
			<content:encoded><![CDATA[<p>If you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus.</p>
<p>I like to have this same ability when I'm writing ActionScript to resize objects proportionately too.<br />
Here I use the functions to set the sizes so when I set width, height is changed accordingly.<br />
The same for setting height, the width is changed accordingly.</p>
<p><em>*Note: I set the inputs to limit the width and height to 500.</em><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_constrain_size_1188717597"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/sizing/constrain_size.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/sizing/constrain_size.swf"
			name="fm_constrain_size_1188717597"
			width="550"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here are two functions for performing proportional resizing by both width and height...<br />
<span id="more-25"></span></p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">/*---------------------------------------------
Resize proportionately by width.
Returns an Object with new proportionate &quot;width&quot; and &quot;height&quot; properties.
After passing the current width, current height and  a new width.
-----------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> constrainSizeToWidth<span style="color: #66cc66;">&#40;</span>oldW:<span style="color: #0066CC;">Number</span>,oldH:<span style="color: #0066CC;">Number</span>,newW:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:newW,<span style="color: #0066CC;">height</span>:newW / oldW * oldH<span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------------------------
Resize proportionately by height.
Returns an Object with new proportionate &quot;width&quot; and &quot;height&quot; properties.
After passing the current width, current height and  a new height.
-----------------------------------------------*/</span>
<span style="color: #000000; font-weight: bold;">function</span> constrainSizeToHeight<span style="color: #66cc66;">&#40;</span>oldW:<span style="color: #0066CC;">Number</span>,oldH:<span style="color: #0066CC;">Number</span>,newH:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:newH / oldH * oldW,<span style="color: #0066CC;">height</span>:newH<span style="color: #66cc66;">&#125;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/&ztz=Resizing width and height proportionately'><img src='http://keith-hair.net/blog/wp-content/plugins/hexosearch-button/logo16x16.png' width='16' height='16' border='0' style='vertical-align:middle' alt='Vote in HexoSearch' title='Vote in HexoSearch' /></a>]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2008/10/13/resizing-width-and-height-proportionately/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
