﻿<?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; Keith H</title>
	<atom:link href="http://keith-hair.net/blog/author/admin/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.1</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>Capitalize a String</title>
		<link>http://keith-hair.net/blog/2012/01/11/capitalize-a-string/</link>
		<comments>http://keith-hair.net/blog/2012/01/11/capitalize-a-string/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 10:27:41 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[capitalization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=443</guid>
		<description><![CDATA[A simple function to help dynamically capitalize text and an excuse to try writing script with the WebMaster Android app, then post it from the WordPress Android app. Nice little script editor for a smart phone or tablet. Even though this function and post are small, writing them from a little smart phone is "capital" [...]]]></description>
			<content:encoded><![CDATA[<p><strong><div id="c1" class="wp-caption alignleft" style="width: 350px"><img class="alignleft" title="Sentence a String to Capital Punishment." alt="image" src="http://keith-hair.net/blog/wp-content/uploads/2012/01/wpid-court-gavel3.jpg" /><br />
<p class="wp-caption-text">Sentence a String to Capital Punishment.</p></div></strong>A simple function to help dynamically capitalize text and an excuse to try writing script with the WebMaster Android app, then post it from the WordPress Android app. Nice little script editor for a smart phone or tablet.</p>
<p>Even though this function and post are small, writing them from a little smart phone is "capital" punishment. After previewing my post I ending up logging into a desktop browser anyway to correct formatting which the WordPress mobile app could not handle from my script example below. Writing script from a small device is also uncomfortable. Using a tablet would be easier but does not necessarily make a lighter "sentence".</p>
<p class="clear">
<pre class="brush: jscript; title: ; notranslate">

&lt;script type=&quot;text/javascript&quot;&gt;
var word=&quot;keith&quot;;
document.write(word);
/**
* Capitalizes the first letter of String.*
**/
function capitalize(W)
{
    return W.substr(0,1).toUpperCase()+W.substr(1,W.length);
}
&lt;/script&gt;
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2012/01/11/capitalize-a-string/&ztz=Capitalize a 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/11/capitalize-a-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>0</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>0</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>0</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_1646711506"
			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_1646711506"
			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_106637738"
			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_106637738"
			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_441625980"
			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_441625980"
			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>3</slash:comments>
		</item>
	</channel>
</rss>

