﻿<?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; ActionScript 3</title>
	<atom:link href="http://keith-hair.net/blog/category/actionscript-3/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>Concatenation Tool</title>
		<link>http://keith-hair.net/blog/2012/01/08/concatenation-tool/</link>
		<comments>http://keith-hair.net/blog/2012/01/08/concatenation-tool/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 09:41:13 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSFL]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[combo]]></category>
		<category><![CDATA[Concatenation]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[videogames]]></category>
		<category><![CDATA[XUL]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=393</guid>
		<description><![CDATA[String'n together combos isn't always as fun as doing them in a fighting videogame. If you write script that has a lot String content mixed with variables, I'm sure you're doing a lot of heavy concatenation. Building string combos with quotes and apostrophes sprinkled all over a script gets confusing. The way I like to [...]]]></description>
			<content:encoded><![CDATA[<p>String'n together combos isn't always as fun as doing them in a fighting videogame.<a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/Tekken-Street-2-Piki_thumb.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/Tekken-Street-2-Piki_thumb-150x150.jpg" alt="" title="Tekken-Street-2-Piki_thumb" width="150" height="150" class="alignleft size-thumbnail wp-image-431" /></a><a href="http://keith-hair.net/works/2011/concatenator/" target="_blank"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/concatenatorUI1-150x150.jpg" alt="" title="concatenatorUI" width="150" height="150" class="alignright size-thumbnail wp-image-441" /></a></p>
<p>If you write script that has a lot String content mixed with variables, I'm sure you're doing a lot of heavy concatenation.<br />
Building string combos with quotes and apostrophes sprinkled all over a script gets confusing. The way I like to keep this confusion to a minimum is to write my static markup separately. This allows me to make sure it shows up as intended. Then I concatenate my variables in all the places that need to have dynamic content.</p>
<p>Taking static markup or script and wrapping quotes around every line is a chore so I made this <a href="http://keith-hair.net/works/2011/concatenator/" title="Concatenation Tool" target="_blank">Concatenation Tool</a> to help with that.</p>
<p>Currently I've only made this support languages I'm using mostly. If I have to use a new language I'd just add it in.<br />
<span id="more-393"></span></p>
<p>Below are some basic use case examples of where a concatenation tool can be useful. </p>
<hr></hr>
<p><strong>JavaScript</strong><br />
<em>Concatenating a content to add to a Jquery UI Dialog.<br />
In this example I purposely used he "text()" method to show the XML content instead of "html()".</em></p>
<pre class="brush: jscript; title: ; notranslate">
    &lt;script type=&quot;text/javascript&quot;&gt;
                $(document).ready(function(){
                var ns = &quot;&quot;;
                ns += &quot;&lt;LIBRARY&gt;&quot;;
                ns += &quot;    &lt;BOOK&gt;&quot;;
                ns += &quot;        &lt;TITLE id=\&quot;2356\&quot;&gt;Charlotte's Web&lt;/TITLE&gt;&quot;;
                ns += &quot;        &lt;AUTHOR&gt;E. B. White&lt;/AUTHOR&gt;&quot;;
                ns += &quot;        &lt;FAMOUS_SAYING&gt;\&quot;Always be on the lookout for the presence of wonder.\&quot;&lt;/FAMOUS_SAYING&gt;&quot;;
                ns += &quot;    &lt;/BOOK&gt;&quot;;
                ns += &quot;    &lt;BOOK&gt;&quot;;
                ns += &quot;        &lt;TITLE id=\&quot;95\&quot;&gt;Scuffy the Tugboat&lt;/TITLE&gt;&quot;;
                ns += &quot;        &lt;AUTHOR&gt;Gertrude Crampton&lt;/AUTHOR&gt;&quot;;
                ns += &quot;        &lt;FAMOUS_SAYING&gt;\&quot;Toot, tooot!\&quot; cried the frightened tugboat.&lt;/FAMOUS_SAYING&gt;&quot;;
                ns += &quot;    &lt;/BOOK&gt;&quot;;
                ns += &quot;&lt;/LIBRARY&gt;&quot;;
                $(&quot;#myDialog&quot;).dialog({width:400, height:400});
                $(&quot;#myDialog p&quot;).text(ns);
                });
    &lt;/script&gt;
</pre>
<p><a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/jqueryui_sample.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/jqueryui_sample.jpg" alt="" title="jqueryui_sample" width="462" height="427" class="alignnone size-full wp-image-409" /></a></p>
<hr></hr>
<p><strong>Python</strong><br />
<em>Concatenating with qoutes</em></p>
<pre class="brush: python; title: ; notranslate">
ns = &quot;&quot;
ns += &quot;&lt;LIBRARY&gt;&quot;
ns += &quot;    &lt;BOOK&gt;&quot;
ns += &quot;        &lt;TITLE id=\&quot;2356\&quot;&gt;Charlotte's Web&lt;/TITLE&gt;&quot;
ns += &quot;        &lt;AUTHOR&gt;E. B. White&lt;/AUTHOR&gt;&quot;
ns += &quot;        &lt;FAMOUS_SAYING&gt;\&quot;Always be on the lookout for the presence of wonder.\&quot;&lt;/FAMOUS_SAYING&gt;&quot;
ns += &quot;    &lt;/BOOK&gt;&quot;
ns += &quot;    &lt;BOOK&gt;&quot;
ns += &quot;        &lt;TITLE id=\&quot;95\&quot;&gt;Scuffy the Tugboat&lt;/TITLE&gt;&quot;
ns += &quot;        &lt;AUTHOR&gt;Gertrude Crampton&lt;/AUTHOR&gt;&quot;
ns += &quot;        &lt;FAMOUS_SAYING&gt;\&quot;Toot, tooot!\&quot; cried the frightened tugboat.&lt;/FAMOUS_SAYING&gt;&quot;
ns += &quot;    &lt;/BOOK&gt;&quot;
ns += &quot;&lt;/LIBRARY&gt;&quot;
print(ns)
</pre>
<p><em>Python concatenation with triple quotes to preserve the carriage returns</em></p>
<pre class="brush: python; title: ; notranslate">
ns=&quot;&quot;&quot;&lt;LIBRARY&gt;
    &lt;BOOK&gt;
        &lt;TITLE id=&quot;2356&quot;&gt;Charlotte's Web&lt;/TITLE&gt;
        &lt;AUTHOR&gt;E. B. White&lt;/AUTHOR&gt;
        &lt;FAMOUS_SAYING&gt;&quot;Always be on the lookout for the presence of wonder.&quot;&lt;/FAMOUS_SAYING&gt;
    &lt;/BOOK&gt;
    &lt;BOOK&gt;
        &lt;TITLE id=&quot;95&quot;&gt;Scuffy the Tugboat&lt;/TITLE&gt;
        &lt;AUTHOR&gt;Gertrude Crampton&lt;/AUTHOR&gt;
        &lt;FAMOUS_SAYING&gt;&quot;Toot, tooot!&quot; cried the frightened tugboat.&lt;/FAMOUS_SAYING&gt;
    &lt;/BOOK&gt;
&lt;/LIBRARY&gt;&quot;&quot;&quot;
print(ns)
</pre>
<p><em>Concatenation with regular quotes</em><br />
<a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/samplepy2.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/samplepy2.jpg" alt="" title="Concatenation of blocks of text with triple quotes" width="682" height="358" class="alignnone size-full wp-image-413" /></a></p>
<p><em>Concatenation of blocks of text with triple quotes</em><br />
<a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/samplepy1.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/samplepy1.jpg" alt="" title="Concatenation with regular quotes" width="698" height="357" class="alignnone size-full wp-image-412" /></a></p>
<hr></hr>
<p><strong>JSFL</strong><br />
<em>Concatenating a XUL markup string for building Flash IDE Panel with JSFL.</em></p>
<pre class="brush: jscript; title: ; notranslate">
if(fl.documents.length == 0){
	fl.createDocument(&quot;timeline&quot;);
}
//------------------------------------------------------------
//An existing folder for the panel's source to be written to.
//------------------------------------------------------------
var appFolderName=&quot;jsflUI_sample&quot;;
var date=new Date();
function writePanelSource()
{
	var code = '';
	code += '&lt;overlay&gt;';
	code += '	&lt;dialog id=&quot;app&quot; title=&quot;Sample UI&quot;&gt;';
	code += '		&lt;hbox&gt;';
	code += '			&lt;spacer/&gt;';
	code += '			&lt;button id=&quot;b0&quot; label=&quot;Button&quot;/&gt;';
	code += '		&lt;/hbox&gt;';
	code += '		&lt;separator/&gt;';
	code += '		&lt;vbox&gt;';
	code += '			&lt;label control=&quot;f0&quot; value=&quot;Field 1&quot; align=&quot;left&quot;/&gt;';
	code += '			&lt;textbox id=&quot;f0&quot; size=&quot;50&quot; value=&quot;'+date.toString()+'&quot;/&gt;';
	code += '			&lt;label control=&quot;f1&quot; value=&quot;Field 2:&quot; align=&quot;left&quot;/&gt;';
	code += '			&lt;textbox id=&quot;f1&quot; size=&quot;50&quot; value=&quot;&quot;/&gt;';
	code += '		&lt;/vbox&gt;';
	code += '		&lt;checkbox id=&quot;cb0&quot; label=&quot;Checkbox 1&quot; checked=&quot;false&quot; /&gt;';
	code += '		&lt;checkbox id=&quot;cb1&quot; label=&quot;Checkbox 2&quot; checked=&quot;false&quot; /&gt;';
	code += '	&lt;/dialog&gt;';
	code += '&lt;/overlay&gt;';
	FLfile.write(fl.configURI + &quot;Commands/&quot;+appFolderName+&quot;/panelsource.xml&quot;, code);
	return code;
}

//----------------------------------------------------------------
//Writes the markup to &quot;appFolderName&quot; of Flash's &quot;Commands folder
//----------------------------------------------------------------
writePanelSource();

//-------------------------------
//Open the Panel in Flash's IDE
//-------------------------------
fl.getDocumentDOM().xmlPanel(fl.configURI + &quot;Commands/&quot;+appFolderName+&quot;/panelsource.xml&quot;);
</pre>
<p><em>Panel UI dialog from JSFL</em><br />
<a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/jsflUI_sample.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/jsflUI_sample.jpg" alt="" title="jsflUI_sample" class="alignnone"/></a></p>
<hr></hr>
<p><strong>SharePoint</strong><br />
<em>Concatenating CAML querys.</em></p>
<pre class="brush: jscript; title: ; notranslate">
function getListData()
{
	var clientContext = new SP.ClientContext.get_current();
	var web = clientContext.get_web();
	var userInfoList = web.get_lists().getByTitle('user_list')
	var camlQuery = new SP.CamlQuery();
	var caml = '';
	caml += '&lt;View&gt;';
	caml += '	&lt;Query&gt;';
	caml += '		&lt;OrderBy&gt;';
	caml += '			&lt;FieldRef Name=&quot;Title&quot; Ascending=&quot;False&quot; /&gt;';
	caml += '		&lt;/OrderBy&gt;';
	caml += '	&lt;/Query&gt;';
	caml += '&lt;/View&gt;';
	camlQuery.set_viewXml(caml);
	collListItem = userInfoList.getItems(camlQuery);
	clientContext.load(collListItem);
	var onQuerySucceeded=function(sender, args)
	{
		var oitem;
		var s='';
		var n=0;
		var len=collListItem.get_count();
		var results=[];
		while(n &lt; len)
		{
			oitem = collListItem.itemAt(n);
			s+=&quot;Title:&quot;+oitem.get_item(&quot;Title&quot;)+&quot;&lt;br&gt;&lt;/br&gt;&quot;;
			n++;
		}
		$(&quot;#output&quot;).append(s);
	}
	var onQueryFailed=function(sender, args)
	{
		alert(&quot;Failed getting data.&quot;)
	}
	clientContext.executeQueryAsync
        (
        Function.createDelegate(this, onQuerySucceeded),
        Function.createDelegate(this, onQueryFailed)
        );
}
</pre>
<p><em>Output of Title column from a SharePoint 2010 list.</em><br />
<a href="http://keith-hair.net/blog/wp-content/uploads/2012/01/sharepoint_sample.jpg" rel="lightbox[393]"><img src="http://keith-hair.net/blog/wp-content/uploads/2012/01/sharepoint_sample.jpg" alt="" title="SharePoint output" width="427" height="376" class="alignnone size-full wp-image-423" /></a></p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2012/01/08/concatenation-tool/&ztz=Concatenation Tool'><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/08/concatenation-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Test if an Object is an Array</title>
		<link>http://keith-hair.net/blog/2011/12/08/test-if-an-object-is-an-array/</link>
		<comments>http://keith-hair.net/blog/2011/12/08/test-if-an-object-is-an-array/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 06:21:41 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[EcmaScript]]></category>
		<category><![CDATA[Object]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=373</guid>
		<description><![CDATA[&#160; &#160; &#160; &#160; &#160; &#160; &#160; I been writing JavaScript recently and had to conjure up the older syntax I'd usually write in ActionScript 2 This post is possibly "beating a dead horse" but I'll post it anyway. JavaScript or ActionScript 2 function isArray&#40;o&#41; &#123; return o instanceof Array; &#160; //Alternative way //return Object(o.constructor) [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" src="/images/beating-a-dead-horse.jpg" alt="" width="255" height="169" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>I been writing JavaScript recently and had to conjure up the older syntax I'd usually write in ActionScript 2<br />
This post is possibly <a href="http://idioms.thefreedictionary.com/beat+a+dead+horse">"beating a dead horse"</a> but I'll post it anyway.</p>
<p><strong>JavaScript or ActionScript 2</strong></p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> isArray<span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> o <span style="color: #000066; font-weight: bold;">instanceof</span> Array;
&nbsp;
    <span style="color: #009900; font-style: italic;">//Alternative way</span>
    <span style="color: #009900; font-style: italic;">//return Object(o.constructor) == [].constructor;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> A=<span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">var</span> B=<span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">var</span> C=<span style="color: #3366CC;">&quot;dog&quot;</span>;
<span style="color: #003366; font-weight: bold;">var</span> D=<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>isArray<span style="color: #66cc66;">&#40;</span>A<span style="color: #66cc66;">&#41;</span>+<span style="color: #3366CC;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>B<span style="color: #66cc66;">&#41;</span>+<span style="color: #3366CC;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span>+<span style="color: #3366CC;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>D<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">//Outputs: true,false,false,false</span></pre>
<p><strong>ActionScript 3</strong></p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> isArray<span style="color: #66cc66;">&#40;</span>o:<span style="color: #0066CC;">Object</span>=<span style="color: #000000; font-weight: bold;">null</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> o is <span style="color: #0066CC;">Array</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> A:<span style="color: #0066CC;">Array</span>=<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> B:<span style="color: #0066CC;">Object</span>=<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> C:<span style="color: #0066CC;">String</span>=<span style="color: #ff0000;">&quot;dog&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> D:<span style="color: #000000; font-weight: bold;">Function</span>=<span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>isArray<span style="color: #66cc66;">&#40;</span>A<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>B<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;,&quot;</span>+isArray<span style="color: #66cc66;">&#40;</span>D<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//Outputs: true,false,false,false</span></pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2011/12/08/test-if-an-object-is-an-array/&ztz=Test if an Object is an Array'><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/12/08/test-if-an-object-is-an-array/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>Appending Nodes to an XMLList in AS3</title>
		<link>http://keith-hair.net/blog/2011/10/08/appending-nodes-to-an-xmllist-in-as3/</link>
		<comments>http://keith-hair.net/blog/2011/10/08/appending-nodes-to-an-xmllist-in-as3/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 01:40:49 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[appendChild]]></category>
		<category><![CDATA[compound assignment]]></category>
		<category><![CDATA[e4x]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[XMLList]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=344</guid>
		<description><![CDATA[Recently I was working with an XMLList variable and I wanted to add a new XML node to an XMLList. My first thought was to just use the "appendChild" method as you would with an XML object. I wasn't really aware of how to do this, and I did not see an XMLList method listed [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working with an XMLList variable and I wanted to add a new XML node to an XMLList.<br />
My first thought was to just use the "appendChild" method as you would with an XML object.<br />
I wasn't really aware of how to do this, and I did not see an XMLList method listed for appending childs in the AS3 documentation.<br />
So I "googled" the term "E4X specification" and read about the "compound assignment operator +=".<br />
Wow using "+=" was really simple. </p>
<p>In the example below I was trying to add a new PAGE node to the existing "PAGE" XMLList....</p>
<p><br></br><br />
<br></br><br />
<strong>Before when I used "appendChild". Error!<br />
Even if my XMLList had one child, it would not be the result I wanted.</strong></p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> doc:<span style="color: #0066CC;">XML</span>=
&lt;BOOK&gt;
	&lt;PAGE /&gt;
	&lt;PAGE /&gt;
	&lt;PAGE /&gt;
&lt;/BOOK&gt;;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Original...&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>doc.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
doc.<span style="color: #006600;">PAGE</span>.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>&lt;PAGE /&gt;<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Changes...&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>doc.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
\\<span style="color: #0066CC;">Trace</span> Output:
Original...
&lt;BOOK&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
&lt;/BOOK&gt;
TypeError: <span style="color: #0066CC;">Error</span> <span style="color: #808080; font-style: italic;">#1086: The appendChild method only works on lists containing one item.</span>
	at XMLList/http:<span style="color: #808080; font-style: italic;">//adobe.com/AS3/2006/builtin::appendChild()</span>
	at Untitled_fla::MainTimeline/Untitled_fla::frame1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p><br></br><br />
<br></br><br />
<strong>Using the compound assignment operator "+=" gives the result I was looking for. The new PAGE node is added to the XMLList.</strong></p>
<pre class="actionscript">&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> doc:<span style="color: #0066CC;">XML</span>=
&lt;BOOK&gt;
	&lt;PAGE /&gt;
	&lt;PAGE /&gt;
	&lt;PAGE /&gt;
&lt;/BOOK&gt;;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Original...&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>doc.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
doc.<span style="color: #006600;">PAGE</span>+=&lt;PAGE /&gt;; <span style="color: #808080; font-style: italic;">//doc.PAGE=doc.PAGE+&lt;PAGE /&gt;; works just as well.</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Changes...&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>doc.<span style="color: #006600;">toXMLString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
\\<span style="color: #0066CC;">Trace</span> Output:
Original...
&lt;BOOK&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
&lt;/BOOK&gt;
&nbsp;
Changes...
&lt;BOOK&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
  &lt;PAGE/&gt;
&lt;/BOOK&gt;
&nbsp;</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2011/10/08/appending-nodes-to-an-xmllist-in-as3/&ztz=Appending Nodes to an XMLList 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/08/appending-nodes-to-an-xmllist-in-as3/feed/</wfw:commentRss>
		<slash:comments>2</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_559285356"
			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_559285356"
			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_163971801"
			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_163971801"
			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>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_1557235401"
			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_1557235401"
			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>Different signs of Cosine, Sine, and Tangent functions and radians</title>
		<link>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/</link>
		<comments>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:27:43 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[cartesian]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[Cosine]]></category>
		<category><![CDATA[quadrants]]></category>
		<category><![CDATA[Sine]]></category>
		<category><![CDATA[Tangent]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=176</guid>
		<description><![CDATA[This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane [...]]]></description>
			<content:encoded><![CDATA[<p>
This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane will be located in one of these 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = (+,+)<br />
Quadrant 2 = (-,+)<br />
Quadrant 3 = (-,-)<br />
Quadrant 4 = (-,+)</strong></p></blockquote>
<p>My interest in this post is about the positive or negative sign of what the Cosine, Sine, and Tangent functions return for the same angle...the angle from one Point to another Point. The sign of these 3 Math functions are different also whenever a Point is located in one of the 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = +Sine,+Cosine,+Tangent<br />
Quadrant 2 = +Sine,-Cosine,-Tangent<br />
Quadrant 3 = -Sine,-Cosine,+Tangent<br />
Quadrant 4 = -Sine,+Cosine,-Tangent</strong></p></blockquote>
<p>Personally I don't think the order or name of the quadrants are important, as long as you keep them consistent with the coordinate system. For my usage, I order my quadrants "1,2,3,4" clockwise since ActionScript's radians values go clockwise.</p>
<p>I feel this will become useful sometime in the future for me when dealing with angles of Points and determining their positions relative to each other.<br />
In a future situation I might not be given X and Y information, but may only have angle data instead. Seeing the difference of signs from the Cosign, Sine, Tangent output of the angle value will be helpful clues.</p>
<p>So some things come back to haunt you, if they are the ghosts of my math teachers, I will surely pay attention in class this time <img src='http://keith-hair.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_quadrants_1539010541"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/different_signs/quadrants.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/different_signs/quadrants.swf"
			name="fm_quadrants_1539010541"
			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><br />
<span id="more-176"></span><br />
Note in Flash/Actionscript, (0,0) is wherever you set your registration point of a MovieClip. In this example I centered the registration point in Flash,<br />
so (0,0) of head's coordinate system will sit directly at the center of the head.</p>
<pre class="brush: as3; title: ; notranslate">
	/*=========================================================
	Using &quot;Math.atan2&quot; to get the angle (in radians) between
	the &quot;reddot&quot; and &quot;head&quot;.

	This radian is fed into the &quot;getSign&quot; function so
	we can see the difference of signs.
	===========================================================*/

	var radians=Math.atan2(reddot.y-head.y,reddot.x-head.x);
	var signs:Object=getSigns(radians);
	var output:String=&quot;&quot;;

	output+=&quot;Sine:&quot;+signs.sine;
	output+=&quot;\n&quot;;
	output+=&quot;Cosine:&quot;+signs.cosine;
	output+=&quot;\n&quot;;
	output+=&quot;Tangent:&quot;+signs.tangent;
	output+=&quot;\n&quot;;
	output+=&quot;\n&quot;;
	output+=&quot;Radians:&quot;+radians;

	status.text=output;
</pre>
<pre class="brush: as3; title: ; notranslate">
/*============================================
Returns an object indicating the sign
of the radian's Cosine, Sine and Tangent.
==============================================*/
function getSigns(rad:Number):Object
{
	var o:Object=new Object();
	if(Math.sin(rad) &gt;= 0){
		o.sine=&quot;+&quot;;
	}else{
		o.sine=&quot;-&quot;;
	}
	if(Math.cos(rad) &gt;= 0){
		o.cosine=&quot;+&quot;;
	}else{
		o.cosine=&quot;-&quot;;
	}
	if(Math.tan(rad) &gt;= 0){
		o.tangent=&quot;+&quot;;
	}else{
		o.tangent=&quot;-&quot;;
	}
	return o;
}
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/&ztz=Different signs of Cosine, Sine, and Tangent functions and radians'><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/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

