﻿<?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; Flex</title>
	<atom:link href="http://keith-hair.net/blog/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Sat, 28 Jan 2012 05:04:23 +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>Get an Incremented Filename String</title>
		<link>http://keith-hair.net/blog/2012/01/28/get-an-incremented-filename-string/</link>
		<comments>http://keith-hair.net/blog/2012/01/28/get-an-incremented-filename-string/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 04:59:02 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[concatenate]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[filepath]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[next file]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=464</guid>
		<description><![CDATA[Some software have the ability to detect the presence of files named in a sequential order. I want to add similar functionality to some experimental scripts I'm working on. For my purposes I'm only focusing on sequential files with numeric prefixes or suffixes in the filenames. The function I've written returns a new filepath thats [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/incremented_file.jpg" rel="lightbox[464]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/incremented_file.jpg" alt="Incremented file image" title="incremented_file" width="175" height="128" class="alignleft size-full wp-image-475" /></a><br />
Some software have the ability to detect the presence of files named in a sequential order.<br />
I want to add similar functionality to some experimental scripts I'm working on.<br />
For my purposes I'm only focusing on sequential files with numeric prefixes or suffixes in the filenames.<br />
The function I've written returns a new filepath thats incremented. Using regular expressions I diced the filepath up into pieces I could change then concatenate into the next potential filepath. This function is for generating a possible next filepath, so testing the existence of the actual file is not my concern.</p>
<p><br></br></p>
<p><strong>Example 1</strong></p>
<pre class="brush: as3; title: ; notranslate">
trace(getIncrementFilePath(&quot;gallery/image01.png&quot;)); //returns gallery/image02.png
</pre>
<p><strong>Example 2</strong><br />
<em>Creating incremented filepaths in a loop.</em></p>
<pre class="brush: as3; title: ; notranslate">
var path:String=&quot;gallery/image01.png&quot;;

var i:int=0;
while (i &lt; 10)
{
	path=getIncrementFilePath(path);
	trace(path);
	i++;
}

/*
trace output
===================
gallery/image02.png
gallery/image03.png
gallery/image04.png
gallery/image05.png
gallery/image06.png
gallery/image07.png
gallery/image08.png
gallery/image09.png
gallery/image10.png
gallery/image11.png
*/
</pre>
<p><span id="more-464"></span></p>
<p><strong>The source </strong></p>
<pre class="brush: as3; title: ; notranslate">
/**
 * Gets a new filepath with incremented digits .
 *
 * @param filepath The filepath to get an incremented filepath from.
 * @param incrementPrefix If true, any digit prefixes will be incremented in the filepath. This is false by default.
 * @param incrementSuffix If true, any digit suffixes will be incremented in the filepath. This is true by default.
 * @return A filepath with the filename's digit suffix or prefix incremented.
 * Returns an empty String if there are no numbers to increment.
 **/
function getIncrementFilePath(filepath:String=&quot;&quot;,incrementPrefix:Boolean=false,incrementSuffix:Boolean=true):String
{
	var s:String=&quot;&quot;;
	var bre:RegExp=/^\d+/mig;
	var ere:RegExp=/\d+$/mig;
	var dpath:String=(filepath.match(/^.+\//mig)[0])||&quot;&quot;;
	var fs:String=filepath.replace(/^.+(\/|\\)/mig,&quot;&quot;);
	var ext:String=fs.replace(/^.+\./mig,&quot;&quot;);
	var fn:String=fs.replace(/\.\w+$/mig,&quot;&quot;);
	var bd:String=(fn.match(bre))[0]||&quot;&quot;;
	var ed:String=(fn.match(ere))[0]||&quot;&quot;;
	var mids:String=fn.replace(bre,&quot;&quot;).replace(ere,&quot;&quot;);
	var md:String=mids.replace(/^[^\d]+|[^\d]+$/mig,&quot;&quot;);
	var dlen:int;
	var tempstr:String=&quot;&quot;;
	var tempn:int;
	var n:int=0;
	if (incrementPrefix)
	{
		if (bd == &quot;&quot;)
		{
			return &quot;&quot;;
		}
		dlen=String((bd.match(/^0+/mig)[0])||&quot;&quot;).length;
		tempn=parseInt(bd)+1;
		while (n &lt; dlen)
		{
			tempstr+=&quot;0&quot;;
			n++;
		}
		if (String(tempstr+tempn).length &gt; bd.length)
		{
			tempstr=tempstr.substr(1,tempstr.length);
		}
		bd=tempstr+tempn;
	}
	if (incrementSuffix)
	{
		if (ed == &quot;&quot;)
		{
			return &quot;&quot;;
		}
		dlen=String((ed.match(/^0+/mig)[0])||&quot;&quot;).length;
		tempn=parseInt(ed)+1;
		while (n &lt; dlen)
		{
			tempstr+=&quot;0&quot;;
			n++;
		}
		if (String(tempstr+tempn).length &gt; ed.length)
		{
			tempstr=tempstr.substr(1,tempstr.length);
		}
		ed=tempstr+tempn;
	}
	if (ext != &quot;&quot;)
	{
		ext=&quot;.&quot;+ext;
	}
	s=dpath+bd+mids+ed+ext;
	return s;
}
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2012/01/28/get-an-incremented-filename-string/&ztz=Get an Incremented Filename String'><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/2012/01/28/get-an-incremented-filename-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting an XMLList to an Array in AS3</title>
		<link>http://keith-hair.net/blog/2011/10/10/converting-an-xmllist-to-an-array-in-as3/</link>
		<comments>http://keith-hair.net/blog/2011/10/10/converting-an-xmllist-to-an-array-in-as3/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 02:51:00 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xmllistToArray XMLList Array String]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/2011/10/10/converting-an-xmllist-to-an-array-in-as3/</guid>
		<description><![CDATA[I wanted to create a list of Strings from only the attributes of an XMLList, and I wanted them separated with carriage returns. The "toXMLString()" method does this automatically on attributes. Attributes are typed as XMLList. &#160; var myXmlList:XMLList=XMLList&#40;&#60;B&#62;&#60;P name=&#34;Orange&#34;/&#62;&#60;P name=&#34;Grape&#34;/&#62;&#60;P name=&#34;Pear&#34;/&#62;&#60;/B&#62;&#41;.P; trace&#40;myXmlList..@name.toXMLString&#40;&#41;&#41;; //Outputs multiple values of all &#34;name&#34; attributes separated with carriage returns automatically. Orange [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to create a list of Strings from only the attributes of an XMLList, and I wanted them separated with carriage returns.</p>
<p>The "toXMLString()" method does this automatically on attributes.<br />
Attributes are typed as XMLList.</p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myXmlList:XMLList=XMLList<span style="color: #66cc66;">&#40;</span>&lt;B&gt;&lt;P <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Orange&quot;</span>/&gt;&lt;P <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Grape&quot;</span>/&gt;&lt;P <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;Pear&quot;</span>/&gt;&lt;/B&gt;<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">P</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>myXmlList..@<span style="color: #0066CC;">name</span>.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//Outputs multiple values of all &quot;name&quot; attributes separated with carriage returns automatically.</span>
Orange
Grape
Pear
&nbsp;</pre>
<p><strong>Putting the values of an XMLList as an Array might be useful also.</strong></p>
<p>Being separated by carriage returns makes it easy to convert to an Array by using the String "split" method.</p>
<p>Wrap this into a function for easy use.</p>
<p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> xmllistToArray<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">list</span>:XMLList<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span>
             <span style="color: #66cc66;">&#123;</span>
                 <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">list</span>.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
             <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2011/10/10/converting-an-xmllist-to-an-array-in-as3/&ztz=Converting an XMLList to an Array in AS3'><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/2011/10/10/converting-an-xmllist-to-an-array-in-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Searching Text Next Previous All in Flash Builder</title>
		<link>http://keith-hair.net/blog/2011/07/23/searching-text-nextpreviousall-in-flash-builder/</link>
		<comments>http://keith-hair.net/blog/2011/07/23/searching-text-nextpreviousall-in-flash-builder/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 20:40:33 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[find all]]></category>
		<category><![CDATA[find next]]></category>
		<category><![CDATA[find previous]]></category>
		<category><![CDATA[highlighting text]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[text search]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=326</guid>
		<description><![CDATA[Here is some Flash Builder script that does basic text search functionality. It will find the index of the search and scroll a TextArea component to the String. I'm using "indexOf" and "lastIndexOf" to perform the next and previous searches. I'd like to use Regular Expressions to find the next and previous occurrences in my [...]]]></description>
			<content:encoded><![CDATA[<p>Here is some Flash Builder script that does basic text search functionality.<br />
It will find the index of the search and scroll a TextArea component to the String.<br />
I'm using "indexOf" and "lastIndexOf" to perform the next and previous searches. I'd like to use Regular Expressions to find the next and previous occurrences in my search, but did not figure that out or know if it's possible to apply it for this.<br />
If anyone knows a faster way let me know.<br />
<br></br><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_FindProject_718552191"
			class="flashmovie"
			width="550"
			height="500">
	<param name="movie" value="/blog/examples/findtext/FindProject.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/findtext/FindProject.swf"
			name="fm_FindProject_718552191"
			width="550"
			height="500">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-326"></span><br />
<a href="/blog/examples/findtext/srcview/" title="View Source">View Source</a></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2011/07/23/searching-text-nextpreviousall-in-flash-builder/&ztz=Searching Text Next Previous All in Flash Builder'><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/2011/07/23/searching-text-nextpreviousall-in-flash-builder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KeyManager revisted for Flex and AS3 Projects</title>
		<link>http://keith-hair.net/blog/2011/02/20/keymanager-revisted-for-flex-and-as3-projects/</link>
		<comments>http://keith-hair.net/blog/2011/02/20/keymanager-revisted-for-flex-and-as3-projects/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 19:47:34 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game Logic]]></category>
		<category><![CDATA[Gatekeeper]]></category>
		<category><![CDATA[Ghostbusters]]></category>
		<category><![CDATA[Gozer]]></category>
		<category><![CDATA[key codes]]></category>
		<category><![CDATA[KeyboardEvent]]></category>
		<category><![CDATA[KeyManager]]></category>
		<category><![CDATA[Keymaster]]></category>
		<category><![CDATA[Keys]]></category>
		<category><![CDATA[Preventing Sticky Keys]]></category>
		<category><![CDATA[State]]></category>
		<category><![CDATA[Zuul]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=293</guid>
		<description><![CDATA[Dana Barrett: Are you the Keymaster? Dr. Peter Venkman: Yes. Actually I'm a friend of his, he asked me to meet him here. -Ghostbusters It's been a whole year since I needed to use the KeyManager class and from comments I've been made aware of bugs in my script. I was hoping the scripts would [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="/blog/examples/keymanagerexample/rick_moranis_ghostbusters.jpg" alt="Rick Moranis as Louis Tully in Ghostbusters." /></p>
<blockquote>
<p style="text-align: left;"><em>Dana Barrett: Are you the Keymaster?<br />
Dr. Peter Venkman: Yes. Actually I'm a friend of his, he asked me to meet him here.</em><br />
-Ghostbusters</p>
</blockquote>
<p style="text-align: right;">
<p>It's been a whole year since I needed to use the KeyManager class and from comments I've been made aware of bugs in my script.<br />
I was hoping the scripts would be a sufficient start that should issues arrive, others would come up with work-a-rounds. (Thank you to all who noted solutions and problems.)</p>
<p>Lately I was needing to write some keyboard interactivity again and I wanted to add some features to help simplify newer task...also fix a couple of things in the process.<br />
In Flex, a lot of coding deals with listening to events. The KeyManager needed events for the tasks I was working on. Callback functions where ok at first but adding "KEY_DOWN", "KEY_UP" and "KEY_SEQUENCE" events help make the class more useful for monitoring status. Monitoring events give more options for handling  keyboard activity in one handler function versus using a separate function for each keyboard combination. So now I've updated the class to have both.<br />
<span id="more-293"></span><br />
<strong>This is a simple example of using the KeyManager class with the added features and KeyManagerEvent.</strong><br />
The example application displays the key activity as you press assigned keys. The functions executed should give a simple idea of how you could expand and add your own application/game logic.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_KeyManagerExample_1432051098"
			class="flashmovie"
			width="550"
			height="600">
	<param name="movie" value="/blog/examples/keymanagerexample/KeyManagerExample.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/keymanagerexample/KeyManagerExample.swf"
			name="fm_KeyManagerExample_1432051098"
			width="550"
			height="600">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<strong><br />
Missing a few keys</strong><br />
Making something process the fastest is great, but sometimes making something easier is more valuable. With the KeyManager I wanted to assign key combinations with simple String dialect instead of writing a long Keyboard constant. Writing "f1" is much easier than "Keyboard.F1". I tried making the size of the class small by NOT including a big list of all Keyboard constants. The "findKey" method was an attempt to dynamically find the key codes instead. Because of that, the first KeyManager I released did not capture some keys like "F1". To fix this, I went halfway by manually checking some Keyboard constants directly and others dynamically. Attempting it this way was for ease of use like using simple Strings like "up" and "down" but also to make key capturing more robust to capture each key that Flash ActionScript does support.</p>
<p>The KeyManager is written for Flex and AS3 only projects.<br />
I decided to share this class since it solves my current task, but I know it is not a solution for everything. Feel free to comment on it's issues or what's needed.<br />
<a href="/blog/examples/keymanagerexample/srcview/index.html">View Source</a></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2011/02/20/keymanager-revisted-for-flex-and-as3-projects/&ztz=KeyManager revisted for Flex and AS3 Projects'><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/2011/02/20/keymanager-revisted-for-flex-and-as3-projects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Is application ran from editor or online?</title>
		<link>http://keith-hair.net/blog/2011/01/20/is-application-ran-from-editor-or-online/</link>
		<comments>http://keith-hair.net/blog/2011/01/20/is-application-ran-from-editor-or-online/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 06:17:06 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=275</guid>
		<description><![CDATA[For most situations when I want to only execute code of an application running from the editor, I use regular expressions to check the application's url. You could use other regular expressions for your own situation. In Flash Builder 4 &#160; &#160; public static function isDevEnvironment&#40;&#41;:Boolean &#123; return mx.core.FlexGlobals.topLevelApplication.url.search&#40;/^file&#124;^\w:\\ig/&#41; != -1; &#125; &#160; In Flex [...]]]></description>
			<content:encoded><![CDATA[<p>For most situations when I want to only execute code of an application running from the editor, I use regular expressions to check the application's url.<br />
You could use other regular expressions for your own situation.</p>
<p><strong>In Flash Builder 4</strong></p>
<pre class="actionscript">&nbsp;
&nbsp;
                        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> isDevEnvironment<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">return</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">FlexGlobals</span>.<span style="color: #006600;">topLevelApplication</span>.<span style="color: #0066CC;">url</span>.<span style="color: #006600;">search</span><span style="color: #66cc66;">&#40;</span>/^file|^\w:\\ig/<span style="color: #66cc66;">&#41;</span> != <span style="color: #cc66cc;">-1</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><strong>In Flex Builder 3</strong></p>
<pre class="actionscript">&nbsp;
			<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> isDevEnvironment<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">return</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">Application</span>.<span style="color: #006600;">application</span>.<span style="color: #0066CC;">url</span>.<span style="color: #006600;">search</span><span style="color: #66cc66;">&#40;</span>/^file|^\w:\\ig/<span style="color: #66cc66;">&#41;</span> != <span style="color: #cc66cc;">-1</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/2011/01/20/is-application-ran-from-editor-or-online/&ztz=Is application ran from editor or online?'><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/2011/01/20/is-application-ran-from-editor-or-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Draggable TitleWindows in Flash Builder</title>
		<link>http://keith-hair.net/blog/2010/11/18/draggable-titlewindows-in-flash-builder/</link>
		<comments>http://keith-hair.net/blog/2010/11/18/draggable-titlewindows-in-flash-builder/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 04:28:57 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[TitleWindow]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=240</guid>
		<description><![CDATA[I like using MXML because it is quicker than writing ActionScript for a lot tasks. When you create a TitleWindow in MXML, it is not draggable. To make a TitleWindow draggable you have to create the window in ActionScript using the PopUpManager methods "createPopUp" or "addPopUp" I wanted this process simpler so that next time [...]]]></description>
			<content:encoded><![CDATA[<p>I like using MXML because it is quicker than writing ActionScript for a lot tasks.<br />
When you create a TitleWindow in MXML, it is not draggable.<br />
To make a TitleWindow draggable you have to create the window in ActionScript using the PopUpManager methods "createPopUp" or "addPopUp"<br />
I wanted this process simpler so that next time I wanted a draggable window, I could just use a simple MXML tag.</p>
<p>Here I extended the TitleWindow to make it be automatically added with the PopUpManager.<br />
Also all the child components get carried over after PopUpManager is used.<br />
I did this so I could lazily use MXML and all references to this component instance stay intact, because the PopUpManager is using the same instance of the MXML component.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_WindowsProject_815309609"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/draggabletitlewindow/WindowsProject.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/draggabletitlewindow/WindowsProject.swf"
			name="fm_WindowsProject_815309609"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The "Move Left" and "Move Right" buttons show that the references are ok.</p>
<p><span id="more-240"></span></p>
<p>MXML in "net/keithhair/FloatWindow.mxml"</p>
<pre class="actionscript">&nbsp;
&lt;?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?&gt;
&lt;s:TitleWindow creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span>
			   xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span>
			   autoLayout=<span style="color: #ff0000;">&quot;true&quot;</span>
			   <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span>
			   <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span>&gt;
	&lt;fx:Script&gt;
		&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">CloseEvent</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">managers</span>.<span style="color: #006600;">PopUpManager</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">Group</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">VGroup</span>;
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">var</span> _vgroup:Group;
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> p:<span style="color: #0066CC;">String</span>;
				<span style="color: #000000; font-weight: bold;">var</span> n:<span style="color: #0066CC;">int</span>;
				<span style="color: #000000; font-weight: bold;">var</span> a:<span style="color: #0066CC;">Array</span>=<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_parent</span>:DisplayObject=parent;
				<span style="color: #808080; font-style: italic;">//---------------------------------------------</span>
				<span style="color: #808080; font-style: italic;">//Remove all the child elements store</span>
				<span style="color: #808080; font-style: italic;">//the references in an Array</span>
				<span style="color: #808080; font-style: italic;">//---------------------------------------------</span>
				n=numElements - <span style="color: #cc66cc;">1</span>;
				<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>n &gt; <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					a.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>removeElementAt<span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					n--;
				<span style="color: #66cc66;">&#125;</span>
				Group<span style="color: #66cc66;">&#40;</span>parent<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">removeElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #808080; font-style: italic;">//---------------------------------------------</span>
				<span style="color: #808080; font-style: italic;">//Add a popup of a this TitleWindow instance,</span>
				<span style="color: #808080; font-style: italic;">//Create a layout container and add all</span>
				<span style="color: #808080; font-style: italic;">//the children back into it.</span>
				<span style="color: #808080; font-style: italic;">//---------------------------------------------</span>
				PopUpManager.<span style="color: #006600;">addPopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #0066CC;">_parent</span><span style="color: #66cc66;">&#41;</span>;
				n=a.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span>;
				_vgroup=<span style="color: #000000; font-weight: bold;">new</span> VGroup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				_vgroup.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;top&quot;</span>,<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
				_vgroup.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;bottom&quot;</span>,<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
				_vgroup.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;left&quot;</span>,<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
				_vgroup.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;right&quot;</span>,<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
				addElement<span style="color: #66cc66;">&#40;</span>_vgroup<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>n &gt; <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					_vgroup.<span style="color: #006600;">addElement</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#91;</span>n<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
					n--;
				<span style="color: #66cc66;">&#125;</span>
				addEventListener<span style="color: #66cc66;">&#40;</span>CloseEvent.<span style="color: #0066CC;">CLOSE</span>, closer<span style="color: #66cc66;">&#41;</span>;
				PopUpManager.<span style="color: #006600;">centerPopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
				p=<span style="color: #000000; font-weight: bold;">null</span>;
				n=<span style="color: #cc66cc;">0</span>;
				a=<span style="color: #000000; font-weight: bold;">null</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			protected <span style="color: #000000; font-weight: bold;">function</span> closer<span style="color: #66cc66;">&#40;</span>evt:CloseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
                                removeEventListener<span style="color: #66cc66;">&#40;</span>CloseEvent.<span style="color: #0066CC;">CLOSE</span>, <span style="color: #0066CC;">arguments</span>.<span style="color: #0066CC;">callee</span><span style="color: #66cc66;">&#41;</span>;
				PopUpManager.<span style="color: #006600;">removePopUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>&gt;
	&lt;/fx:Script&gt;
&lt;/s:TitleWindow&gt;
&nbsp;</pre>
<p>Now I can simply use MXML to make my draggable windows.<br />
The window is draggable and all the<br />
MXML children are there too.</p>
<pre class="actionscript">&nbsp;
	&lt;keithhair:FloatWindow id=<span style="color: #ff0000;">&quot;mywindow&quot;</span>
			       title=<span style="color: #ff0000;">&quot;My Window&quot;</span>
			       <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;250&quot;</span>
			       <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span>&gt;
		&lt;mx:TabNavigator <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span>
				 <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span>&gt;
			&lt;mx:VBox label=<span style="color: #ff0000;">&quot;Buttons&quot;</span>&gt;
				&lt;s:<span style="color: #0066CC;">Button</span>/&gt;
				&lt;s:<span style="color: #0066CC;">Button</span>/&gt;
				&lt;s:<span style="color: #0066CC;">Button</span>/&gt;
			&lt;/mx:VBox&gt;
			&lt;mx:VBox label=<span style="color: #ff0000;">&quot;Checkboxes&quot;</span>&gt;
				&lt;s:CheckBox/&gt;
				&lt;s:CheckBox/&gt;
				&lt;s:CheckBox/&gt;
			&lt;/mx:VBox&gt;
			&lt;mx:VBox label=<span style="color: #ff0000;">&quot;TextAreas&quot;</span>&gt;
				&lt;s:TextArea/&gt;
				&lt;s:TextArea/&gt;
			&lt;/mx:VBox&gt;
		&lt;/mx:TabNavigator&gt;
	&lt;/keithhair:FloatWindow&gt;
&nbsp;</pre>
<p>If you know of a more efficient way that does this or can make this better just add your comments to my blog. </p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/11/18/draggable-titlewindows-in-flash-builder/&ztz=Draggable TitleWindows in Flash Builder'><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/11/18/draggable-titlewindows-in-flash-builder/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Get the view size inside of a Container in Flex</title>
		<link>http://keith-hair.net/blog/2010/05/17/get-the-view-size-inside-of-a-container-in-flex/</link>
		<comments>http://keith-hair.net/blog/2010/05/17/get-the-view-size-inside-of-a-container-in-flex/#comments</comments>
		<pubDate>Mon, 17 May 2010 16:02:22 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[EdgeMetrics]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[Rectangle]]></category>
		<category><![CDATA[viewMetrics]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=229</guid>
		<description><![CDATA[For some odd reason you might want to get the width and height of the inside of a Container. You can use the "viewMetrics" property of a container to do it. In the following example I overlay a green box over a Panel to show how it matches the Panel's size. Comments are welcome. 
<p><a href="/blog/examples/edgemetrics/srcview/SampleProject.zip">Download</a></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/05/17/get-the-view-size-inside-of-a-container-in-flex/&ztz=Get the view size inside of a Container in Flex'><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/05/17/get-the-view-size-inside-of-a-container-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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; title: ; notranslate">
/*****************************************************************************************
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>3</slash:comments>
		</item>
		<item>
		<title>KeyManager Class for Detecting Key Press Combos or Sequences</title>
		<link>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/</link>
		<comments>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 23:30:12 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[ASWD]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[dev mode]]></category>
		<category><![CDATA[easter eggs]]></category>
		<category><![CDATA[key press]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[KeyboardEvent]]></category>
		<category><![CDATA[videogames]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=189</guid>
		<description><![CDATA[When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it... When an app or game is written we "expect" the [...]]]></description>
			<content:encoded><![CDATA[<p>When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it...<img class="alignright" src="/blog/examples/keycontrol/typing.jpg" alt="keyboard" width="264" height="386" /></p>
<p>When an app or game is written we "expect" the user to precisely press the proper key or key combination at a time to execute programmatic actions. However, most of us have ten fingers and we use more than one finger to press more than one button on the keyboard. The expected program reaction from multiple fingered keyboard input might not occur because you have another function executing when you expect just one at a time.<br />
<span id="more-189"></span></p>
<p><strong>Key Combinations</strong><br />
Imagine you are using the keyboard to play a game. The RIGHT arrow key is for moving your character right, the LEFT arrow key is for moving your character LEFT.<br />
Ok, the action in this game is heating up, you are pressing LEFT to avoid the lasers shooting at you. You successfully dodged the lasers, now you press RIGHT to move in and attack...but in the heat of battle, your other finger is still on the LEFT button. What happens now is your character most likely gets stuck, because both movement keys are pressed telling the character to go in opposite directions!</p>
<p>In some cases allowing multiple key presses is how you want the app to react. For example you want the user to press both UP and RIGHT keys to move the characters in a diagonal direction. When to allow this and when not can be different among all of the control buttons. It becomes messy having to write "If" and "switch" statements to make the KeyboardEvent listeners work according to the different controls needed.</p>
<p><strong>Key Sequences</strong><br />
If you love video games cheats or the easter eggs developers sometimes place in apps you'll remember to access them, you will usually enter in a sequence of key presses. If you entered the sequence successfully you would have access to cool game cheats or some special developer mode of an application.</p>
<p><strong>KeyManager</strong><br />
For the above reasons I've written a KeyManager class to add key control that allows individual keys/keycombos the option to cancel out the any previous key/keycombo that are pressed down...and when key/keycombos are released, whatever key/keycombo that are still pressed will be active again. And for detecting key press sequences the KeyManager class will allow also.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_keycontrol_1974521006"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf"
			name="fm_keycontrol_1974521006"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>This is a basic example using KeyManager. The "addKey" method is for adding key press combos and the "addKeySequence" is for obviously adding<br />
key press sequences.</p>
<p>In the working flash example, you can click "singular combos" checkbox to false, to see the problem described previously about the character getting stuck when pressing RIGHT and LEFT key at the same time. When you set the checkbox back to true you will notice how each new key press overrides any others that are still down. This results in responsive execution if a user has a habit of holding down other keys while pressing new ones..</p>
<p><em><strong>Also in the working sample above if you enter in the proper key sequence you will be rewarded with an "Easter Egg" to view the source and FLA.</strong></em></p>
<p><strong>Example usage:</strong></p>
<pre class="brush: as3; title: ; notranslate">
import net.keithhair.KeyManager;

var keyManager:KeyManager;
keyManager=new KeyManager(stage);
keyManager.addKey([&quot;right&quot;], goRight,stopRight,&quot;control1&quot;);
keyManager.addKey([&quot;left&quot;], goLeft,stopLeft,&quot;control2&quot;);
keyManager.addKey([&quot;up&quot;], goUp,stopUp,&quot;control3&quot;);
keyManager.addKey([&quot;down&quot;], goDown,stopDown,&quot;control4&quot;);
keyManager.addKey([&quot;shift&quot;,&quot;w&quot;,&quot;t&quot;], toggleWindow);
keyManager.addKeySequence([&quot;up&quot;,&quot;up&quot;,&quot;down&quot;,&quot;down&quot;,&quot;left&quot;,&quot;right&quot;,&quot;left&quot;,&quot;right&quot;],openEasterEgg);
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/&ztz=KeyManager Class for Detecting Key Press Combos or Sequences'><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/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Everyone gets a turn</title>
		<link>http://keith-hair.net/blog/2009/12/11/everyone-gets-a-turn/</link>
		<comments>http://keith-hair.net/blog/2009/12/11/everyone-gets-a-turn/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 07:14:18 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Components]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[dial]]></category>
		<category><![CDATA[knob]]></category>
		<category><![CDATA[NiceKnob]]></category>
		<category><![CDATA[spin]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=143</guid>
		<description><![CDATA[If everyone got a turn, would you take your turn the same as the others or be different? I've seen lots of really great knobs, dials, and gauge components. The intended way a person would build their app to use one would most likely be varied . That makes each of these kinds of controls  [...]]]></description>
			<content:encoded><![CDATA[<p>If everyone got a turn, would you take your turn the same as the others or be different?</p>
<p>I've seen lots of really great knobs, dials, and gauge components. The intended way a person would build their app to use one would most likely be varied . That makes each of these kinds of controls  special because its difficult to make a control that fits a very broad range of functionality/look-n-feel, and probably why I have yet to see "one knob to rule them all".   Sliders, and Buttons are pretty straight forward, but not the "Knob" type of control.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_DemoKnob_1928296081"
			class="flashmovie"
			width="210"
			height="210">
	<param name="movie" value="http://keith-hair.net/blog/examples/niceknobs2/DemoKnob.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://keith-hair.net/blog/examples/niceknobs2/DemoKnob.swf"
			name="fm_DemoKnob_1928296081"
			width="210"
			height="210">
	<!--<![endif]-->
		
<p style="text-align: center;"><a href="http://adobe.com/go/getflashplayer"><img class="aligncenter" src="http://keith-hair.net/blog/examples/niceknobs2/niceknobs2.jpg" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p style="text-align: left;"><span id="more-143"></span></p>
<p style="text-align: left;">Knobs can be just like a glass of tea. Some like a twist of lemon in it, or twist of lime etc. Just like others who have made their own controls tailor made to their needs, I have done with my knob.  The good thing about that is there's always more than one person who share the same preference on how a knob should function.  I've made many custom knobs that were built for small and simple duties. I'd like to make a knob to share here that is more reusable and cover wider ranges of functionality than the older ones I've built.  The knob displayed here is configurable but not skinnable, I've chosen to draw my knob dynamically with ActionScript's drawing API.  I hope to release this one after fixing some problems in my spare time.</p>
<p style="text-align: left;"><a title="NiceKnobs Revisited" href="http://keith-hair.net/blog/examples/niceknobs2/index.html" target="_blank">View demo</a></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2009/12/11/everyone-gets-a-turn/&ztz=Everyone gets a turn'><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/2009/12/11/everyone-gets-a-turn/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

