<?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>The efnx code blog. &#187; GUI</title>
	<atom:link href="http://efnx.com/tag/gui/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Tue, 15 May 2012 17:46:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>AS3 Window Class (real-time skinnable)</title>
		<link>http://efnx.com/as3-window-class-real-time-skinnable/</link>
		<comments>http://efnx.com/as3-window-class-real-time-skinnable/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 23:38:03 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[windowing]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=39</guid>
		<description><![CDATA[[edit august 21st 2008] Hey guys this code is available but it is messy and the project has been scrapped. I will pick it up again, probably with OpenGL and C++[/edit] In an effort to (maybe) find a new job, depending on what happens with my current one, I&#8217;m releasing a preview of my GUI [...]]]></description>
			<content:encoded><![CDATA[<p>[edit august 21st 2008] Hey guys this code is available but it is messy and the project has been scrapped. I will pick it up again, probably with OpenGL and C++[/edit]</p>
<p>In an effort to (maybe) find a new job, depending on what happens with my current one, I&#8217;m releasing a preview of my GUI classes. This class is a window class. It contains your display objects in a nice, draggable, scrollable and real-time skinnable window. You can make your own graphics for the window and configure button placement, scrollbar offsets, label, offsets and all other text goodies from an external config.xml script. There&#8217;s nothing to keep in your library and it&#8217;s not that big. It would be nice if anyone who uses it can tell me their memory stats, as I&#8217;m currently looking to make sure my code is clean and there are no leaks. Click the link below for a little demo.</p>
<p><a href="http://www.efnx.com/Flash/GUI/GUI.html">Here&#8217;s the demo!</a></p>
<p>If you&#8217;re interested in using the class you can dive in headfirst at your own risk. It&#8217;s kinda long (about 1200 lines). I&#8217;ll be working on completely revising it from the ground up as it really is a big mess right now.</p>
<p>Source: <a href='http://blog.efnx.com/wp-content/uploads/2008/08/guitar.gz' title='GUI - messy'>GUI &#8211; mess</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-window-class-real-time-skinnable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Developing a Pure AS3 GUI &#8211; Part One (Scaling Bars)</title>
		<link>http://efnx.com/developing-a-pure-actionscript-gui-part-one-scaling-bars/</link>
		<comments>http://efnx.com/developing-a-pure-actionscript-gui-part-one-scaling-bars/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 08:33:51 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[scaling bar]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=20</guid>
		<description><![CDATA[This class has been deprecated and phased out as of 12.7.2007 Writing your own GUI can be a daunting task, most people might find it easier to learn MXML and use Flex Builder or Flash Components than to waste their time writing GUI code and Photoshopping images. I on the other hand hate proprietary frameworks [...]]]></description>
			<content:encoded><![CDATA[<p><b>This class has been deprecated and phased out as of 12.7.2007</b></p>
<p>Writing your own GUI can be a daunting task, most people might find it easier to learn MXML and use Flex Builder or Flash Components than to waste their time writing GUI code and Photoshopping images. I on the other hand hate proprietary frameworks [like MXML] and really like the clean approach of creating classes of GUI elements that build on each other to make an interface. This post is the first in a series of posts designed to step through MY method of GUI design. </p>
<p><a href="#example">Example</a><br />
<a href="#source">Source</a></p>
<p>I start the process at windows. Windows hold all the content of a graphical operating system, the mother of all interfaces, so why not start there? Well, windows are super complicated, so first we&#8217;ll start by writing the components of a window. We&#8217;ll need a window bar that holds the close, minimize and optimize buttons and scales to a given size. This means we&#8217;ll need bars [vertical and horizontal] that tile. Don&#8217;t let the name Scaling Bars trick you, these bars aren&#8217;t really scaling, they&#8217;re tiling the bitmaps given to them in the constructor. Here&#8217;s the beginning code where we set up all our variables.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">GUI</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; scalingBar is an object that given three images will scale to a certain size, tiling the middle image //</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; and placing the end images on either side (overall width will be the given size) //////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// usage: bar:scalingBar = new scalingBar(new Array(&quot;toporleftImage.xxx&quot;,&quot;middleImage.xxx&quot;,&quot;bottomorrightImage.xxx&quot;), [tileDir:String: either &quot;horizontal&quot; or &quot;vertical&quot;); &nbsp;//</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; &nbsp; addChild(bar); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; &nbsp; bar.resize(someSize); &nbsp;//</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//////////////////////////////////</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">loadedSprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">aquireResources</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Rectangle</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;<br />
&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> scalingBar <span style="color: #0066CC;">extends</span> Sprite<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tileDirection:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tileSize:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> minimumSize:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> side1:loadedSprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> middle:loadedSprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> side2:loadedSprite;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">loaded</span>:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> testing:<span style="color: #0066CC;">Boolean</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span></div></div>
<p>Okay. We&#8217;ve imported some classes that I&#8217;ve written myself that I haven&#8217;t talked about before, don&#8217;t worry, I&#8217;ve included them in the source and will post about them later. The vars are all pretty self-explanatory. The loadedSprites are a class of Sprite I&#8217;ve developed to make importing graphics a little easier on me. Given a path to an image it simply retrieves the image and sticks it inside a Sprite [itself]. On to the constructor:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> scalingBar<span style="color: #66cc66;">&#40;</span>imagePathArray:<span style="color: #0066CC;">Array</span>, tileDir:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;horizontal&quot;</span>, _testing:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testing = _testing;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tileDirection = tileDir;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection <span style="color: #66cc66;">!</span>= <span style="color: #ff0000;">&quot;horizontal&quot;</span> <span style="color: #66cc66;">&amp;&amp;</span> tileDirection <span style="color: #66cc66;">!</span>= <span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::init: invalid tiling direction, scalingBar only accepts either <span style="color: #000099; font-weight: bold;">\&quot;</span>horizontal<span style="color: #000099; font-weight: bold;">\&quot;</span> or <span style="color: #000099; font-weight: bold;">\&quot;</span>vertical<span style="color: #000099; font-weight: bold;">\&quot;</span>.&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side1 = <span style="color: #000000; font-weight: bold;">new</span> loadedSprite<span style="color: #66cc66;">&#40;</span>imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>, loadCycleComplete, testing<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//remove testing parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle = <span style="color: #000000; font-weight: bold;">new</span> loadedSprite<span style="color: #66cc66;">&#40;</span>imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>, loadCycleComplete, testing<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//to keep from tracing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2 = <span style="color: #000000; font-weight: bold;">new</span> loadedSprite<span style="color: #66cc66;">&#40;</span>imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>, loadCycleComplete, testing<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//verbose info</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side1.<span style="color: #0066CC;">name</span> = imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #0066CC;">name</span> = imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #0066CC;">name</span> = imagePathArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>side1<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>middle<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>side2<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span></div></div>
<p>When instantiating the scalingBar class, create an array consisting of paths to the three images to be used for the bar, the left [or top], the middle, and the right [or bottom]. If left to the defaults your bar will tile and size horizontally. You can pass &#8220;vertical&#8221; as the second parameter to set the bar up to tile horizontally. Next we have the functions that take care of placement and size checks after the images are loaded. loadedSprite operates whatever function was passed to it as the second parameter in its instantiation, so no external event listeners are needed. We passed loadCycleComplete to the loadedSprites so that function will be called each time one is done loading:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadCycleComplete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">loaded</span>++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::loadCycleComplete: has loaded &quot;</span> + <span style="color: #0066CC;">loaded</span> + <span style="color: #ff0000;">&quot;/3 resources. &quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">loaded</span> == <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection == <span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tileSize = middle.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tileSize = middle.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::loadCycleComplete: finished loading.&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; placeParts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateSize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> updateSize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection == <span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minimumSize = side1.<span style="color: #0066CC;">width</span> + side2.<span style="color: #0066CC;">width</span> + tileSize;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::updateSize: side1.width, side2.width, tileSize:&quot;</span> + side1.<span style="color: #0066CC;">width</span>, side2.<span style="color: #0066CC;">width</span>, tileSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minimumSize = side1.<span style="color: #0066CC;">height</span> + side2.<span style="color: #0066CC;">height</span>+ tileSize;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::updateSize: side1.height, side2.height, tileSize:&quot;</span> + side1.<span style="color: #0066CC;">height</span>, side2.<span style="color: #0066CC;">height</span>, tileSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> placeParts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection == <span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">x</span> = side1.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">x</span> = middle.<span style="color: #006600;">x</span> + middle.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">y</span> = side1.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">y</span> = middle.<span style="color: #006600;">y</span> + middle.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span></div></div>
<p>Almost done! The last part is the resize function, which takes an integer size and scales the entire bar either horizontally or vertically, depending on what you have specified. This is the real meat of the class. The resize function moves the bottom [or left] image to the border of the given size, then tiles the middle image over however many times needed until it reaches the bottom [or left] image:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">size</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">size</span> <span style="color: #66cc66;">&gt;</span>= minimumSize<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::resize: valid resize value.&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData = middle.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection == <span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">size</span> - side2.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::resize(): side1,side2 width and minimumSize:&quot;</span> + side1.<span style="color: #0066CC;">width</span>, side2.<span style="color: #0066CC;">height</span>, minimumSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span> = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">size</span> - side1.<span style="color: #0066CC;">width</span> - side2.<span style="color: #0066CC;">width</span>, bmd.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;window::resize(): windowbarmiddle.bitmap.bitmapData: &quot;</span> + middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">width</span>, middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">*</span>bmd.<span style="color: #006600;">width</span><span style="color: #66cc66;">&lt;</span>middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">width</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">copyPixels</span><span style="color: #66cc66;">&#40;</span>bmd, <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, bmd.<span style="color: #0066CC;">width</span>, bmd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">*</span>bmd.<span style="color: #0066CC;">width</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;window::resize(): copying pixels to middle.x=&quot;</span> + i<span style="color: #66cc66;">*</span>bmd.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tileDirection == <span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; side2.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">size</span> - side2.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::resize(): bmd dimensions:&quot;</span> + bmd.<span style="color: #0066CC;">width</span>, bmd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span> = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>bmd.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">size</span> - side1.<span style="color: #0066CC;">height</span> - side2.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;window::resize(): windowbarmiddle.bitmap.bitmapData w,h: &quot;</span> + middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">width</span>, middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">*</span>bmd.<span style="color: #006600;">height</span><span style="color: #66cc66;">&lt;</span>middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">height</span>; i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; middle.<span style="color: #006600;">bitmap</span>.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">copyPixels</span><span style="color: #66cc66;">&#40;</span>bmd, <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, bmd.<span style="color: #0066CC;">width</span>, bmd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, i<span style="color: #66cc66;">*</span>bmd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;window::resize(): copying pixels to middle.y = &quot;</span> + i<span style="color: #66cc66;">*</span>bmd.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>testing<span style="color: #66cc66;">&#41;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;scalingBar::resize: invalid resize value of &quot;</span> + <span style="color: #0066CC;">size</span> + <span style="color: #ff0000;">&quot;, resizing at &quot;</span> + minimumSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resize<span style="color: #66cc66;">&#40;</span>minimumSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #808080; font-style: italic;">//end class</span><br />
<span style="color: #66cc66;">&#125;</span><span style="color: #808080; font-style: italic;">//end package</span></div></div>
<p><a name="example">Example</a><br />
And there we go! Here is an example of the implementation:<br />
<iframe width="100%" height="450" src="http://blog.efnx.com/wp-content/uploads/2007/11/scalingbartest.html"></iframe></p>
<p><a name="source">Source</a><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/11/blogefnxcom-scalingbar.zip' title='scalingBar source'>scalingBar source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/developing-a-pure-actionscript-gui-part-one-scaling-bars/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

