﻿<?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; Resize</title>
	<atom:link href="http://keith-hair.net/blog/tag/resize/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 Flash Documents to Fit Contents in JSFL</title>
		<link>http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/</link>
		<comments>http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 20:04:56 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JSFL]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[Resize]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=219</guid>
		<description><![CDATA[I use Flex for the majority of my Flash related work, even for writing plain ActionScript. Lately I've barely even used the Flash authoring environment to create stuff. When I do use the Flash authoring environment, it's mostly for automation and prep work of content. If you are like me, you write JSFL to do [...]]]></description>
			<content:encoded><![CDATA[<p>I use Flex for the majority of my Flash related work, even for writing plain ActionScript. Lately I've barely even used the Flash authoring environment to create stuff. When I do use the Flash authoring environment, it's mostly for automation and prep work of content. If you are like me, you write JSFL to do that stuff.</p>
<p>I love automating redundant tasks. One thing that bugs me when importing graphical assets to Flash's stage is having to resize the document to what I imported. I like that I can do this by going to the Document Properties and setting the document to match the content size, but if I have to do this each time I import/export content it becomes a irksome chore. I write JSFL scripts that run tasks on multiple files, having a "match contents"  function would be useful to me in my case...maybe to you as well. I do not see a JSFL way to do this. (Maybe there is and I had a brain fart?). Until then, here is a script I wrote to do it in JSFL...<br />
<span id="more-219"></span></p>
<pre class="brush: jscript;">
/*****************************************************************************************
What:	Document_to_Content_Size.jsfl
		JSFL Command for Flash (8+) that will resize the document to fit the content
		that is on the stage in the authoring environment.

Why:		Yep, this action can also be done by going to the Document Properties
		and setting &quot;match&quot; to &quot;contents&quot;. However, I have not
		found a way to do this same action within JSFL script
		If you know a JSFL way to do this same action easier contact me.		

Date:		March 21, 2010
Author:	Keith Hair
Contact	khos2007@gmail.com
Web:		keith-hair.net		

INSTALL:
		If you deal with JSFL you probably know what to do, but anyway...
		Save this script with a &quot;.jsfl&quot; extension and put in:
		&quot;Your Flash installation folder\en\First Run\Commands&quot; folder
		Or just put it anywhere and double-click the file.

LEGAL STUFF:
		This script is free for whatever, just improve it or say hello! 		

NOTE:
		This is primarily for resizing the Flash
		document to fit content that is imported to the stage.
		Resizing is buggy with Component instances.

******************************************************************************************/
fl.outputPanel.clear();
runApp();
function runApp()
{
	var doc=fl.getDocumentDOM();
	var element;
	var docw=1;
	var doch=1;
	var fn=0;
	var ln=0;
	var en=0;
	var tframes;
	var layer;
	var frame;
	var ox;
	var oy;
	var left=null;
	var right=null;
	var top=null;
	var bottom=null;
	var cf=doc.getTimeline().currentFrame;
	while(ln &lt; doc.getTimeline().layerCount)
	{
		layer=doc.getTimeline().layers[ln];
		tframes=layer.frameCount;
		fn=0;
		while(fn &lt; tframes)
		{
			doc.getTimeline().currentFrame = fn;
			frame=layer.frames[fn];
			en=0;
			while(en &lt; frame.elements.length)
			{
				element = frame.elements[en];
				ox=element.x;
				oy=element.y;
				if(left == null){
					left=ox;
				}
				if(right == null){
					right=ox+element.width;
				}
				if(top == null){
					top=oy;
				}
				if(bottom == null){
					bottom=oy+element.height;
				}

				left=Math.min(ox,left);
				right=Math.max(ox+element.width,right);
				top=Math.min(oy,top);
				bottom=Math.max(oy+element.height,bottom);
				en++;
			}
			fn++;
		}
		ln++;
	}
	fl.trace(&quot;CURRENT SIZE--&gt;\t&quot;+doc.width+&quot; x &quot;+doc.height);
	docw=Math.round(right-left);
	doch=Math.round(bottom-top);
	moveAllElementsBy(-left,-top);
	doc.width=docw;
	doc.height=doch;
	fl.trace(&quot;NEW SIZE--&gt;\t\t\t&quot;+doc.width+&quot; x &quot;+doc.height);
	doc.getTimeline().currentFrame=cf;
}

function moveAllElementsBy(tx,ty)
{
	doc=fl.getDocumentDOM();
	var element;
	var fn=0;
	var ln=0;
	var en=0;
	var tframes;
	var layer;
	var frame;
	var otp;
	while(ln &lt; doc.getTimeline().layerCount)
	{
		layer=doc.getTimeline().layers[ln];
		tframes=layer.frameCount;
		fn=0;
		while(fn &lt; tframes)
		{
			doc.getTimeline().currentFrame = fn;
			frame=layer.frames[fn];
			en=0;
			while(en &lt; frame.elements.length)
			{
				element=frame.elements[en];
				element.x+=tx;
				element.y+=ty;
				if(element.elementType.search(/instance|text/mig) == -1){
					element.x+=element.width/2;
					element.y+=element.height/2;
				}

				en++;
			}
			fn++;
		}
		ln++;
	}

}
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/&ztz=Resizing Flash Documents to Fit Contents in JSFL'><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/2010/03/21/resizing-flash-documents-to-fit-contents-in-jsfl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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_1694774453"
			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_1694774453"
			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>
