<?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>Richard Lord &#187; Actionscript</title>
	<atom:link href="http://www.richardlord.net/blog/tag/actionscript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.richardlord.net</link>
	<description>Actionscript/Flex, PHP and Java developer</description>
	<lastBuildDate>Fri, 25 Jun 2010 07:34:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Signals from Robert Penner</title>
		<link>http://www.richardlord.net/blog/signals-from-robert-penner</link>
		<comments>http://www.richardlord.net/blog/signals-from-robert-penner#comments</comments>
		<pubDate>Tue, 08 Sep 2009 07:51:08 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Signals]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/signals-from-robert-penner</guid>
		<description><![CDATA[Robert Penner has just released the source for his event system, called AS3 Signals. It&#8217;s an interesting read and the sort of project I like &#8211; a small feature set in need of good architectural design. And I like the design. I like to think that Robert may have been inspired in part by my [...]]]></description>
			<content:encoded><![CDATA[<p>Robert Penner has just released the source for his event system, called <a href="http://code.google.com/p/as3-signals/">AS3 Signals</a>. It&#8217;s an interesting read and the sort of project I like &#8211; a small feature set in need of good architectural design. And I like the design.</p>

<p>I like to think that Robert may have been inspired in part by my work with <a href="/blog/events-in-actionscript-2">events in AS2</a>, but I doubt it.</p>

<p>The conversation&#8217;s just kicked off on <a href="http://twitter.com/robpenner">Twitter</a> and <a href="http://robertpenner.com/flashblog/2009/09/my-new-as3-event-system-signals.html#comment-form">Robert&#8217;s Blog</a>. Josh McDonald in particular has already made some good suggestions. My comments on bubbling are awaiting moderation.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/signals-from-robert-penner/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The I in Interface</title>
		<link>http://www.richardlord.net/blog/the-i-in-interface</link>
		<comments>http://www.richardlord.net/blog/the-i-in-interface#comments</comments>
		<pubDate>Thu, 06 Aug 2009 14:44:04 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Best practice]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/the-i-in-interface</guid>
		<description><![CDATA[<p>I'm often asked why the interfaces in <a href="http://flintparticles.org">Flint</a> don't start with a letter I. The simple reason is that I think this practice, while common among Actionscript developers, is so seriously flawed that it's better not to do it, even if it is common among other developers and may cause some initial confusion for some...</p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m often asked why the interfaces in <a href="http://flintparticles.org">Flint</a> don&#8217;t start with a letter I. The simple reason is that I think this practice, while common among Actionscript developers, is so seriously flawed that it&#8217;s better not to do it, even if it is common among other developers and may cause some initial confusion for some.</p>

<h3>The argument for</h3>

<p>The only argument I&#8217;ve heard in favour of this practice is that it enables a developer to know whether a type is a class or an interface just by looking at the name, but I&#8217;m not convinced.</p>

<h3>It&#8217;s more confusing</h3>

<p>Looking through the core Actionscript classes, I do a double-take at classes like ID3Info &#8211; (What&#8217;s a D3Info? Oh, it&#8217;s a class not an interface.)</p>

<p>Or, consider what might happen if you were creating an application that interacts with mobile phones. You are very likely to have a type called IPhone. But is that a standard phone interface that all phone classes should implement? Or is it a class for the iPhone implementation?</p>

<h3>Same name, different type</h3>

<p>And it&#8217;s not just confusion over whether something is an interface or not. What makes a class an EventDispatcher? Is it any type that extends EventDispatcher, or is it any type that implements IEventDispatcher. The I is just a prefix indicating that a type is an interface, so we have two EventDispatcher types. Without the I prefix this wouldn&#8217;t be possible.</p>

<h3>But we copied it from Java, didn&#8217;t we?</h3>

<p>Actionscript developers have adopted the I prefix because Adobe did so. But why did Adobe adopt this idea? Common thinking is that they adopted the idea from the Java community, which sounds plausible. Many of the ideas in Actionscript originated in other languages.</p>

<p>However, using an I prefix on interfaces isn&#8217;t a standard in Java. In fact, it&#8217;s just the opposite. Look at any of the <a href="http://java.sun.com/javase/6/docs/api/">Java core api</a>, or any other code developed by Sun, and you&#8217;ll not see an I prefix on the interfaces. And it&#8217;s not just Sun, many other large Java development companies don&#8217;t use the I prefix (<a href="http://code.google.com/p/google-guice/">Google, for example</a>). Far from being a Java standard, the I prefix is an aberration adopted in some corners of the Java world, possibly by ex-Microsoft developers.</p>

<h3>Hungarian Notation</h3>

<p>Why ex-Microsoft developers? Because Microsoft used to use <a href="http://msdn.microsoft.com/en-us/library/aa260976(VS.60).aspx">Hungarian Notation</a> in all their code (Charles Simonyi, who invented Hungarian Notation, became chief architect at Microsoft). The reason Hungarian Notation works is because it requires every name to have a prefix. So iPhone is the Phone interface (i prefix for interface) and cIPhone is the IPhone class (c prefix for class).</p>

<h3>Mixing it</h3>

<p>Problems occur when only some names have prefixes, as with the I prefix for interfaces and no prefix for classes. Unfortunately, this is the pattern that Adobe have adopted for Actionscript (and that Microsoft have adopted for C#, but even C# isn&#8217;t perfect).</p>

<h3>So&#8230;</h3>

<p>This is why I don&#8217;t use the I prefix on interfaces in any of my code, including Flint.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/the-i-in-interface/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Object Pool class</title>
		<link>http://www.richardlord.net/blog/object-pool-class</link>
		<comments>http://www.richardlord.net/blog/object-pool-class#comments</comments>
		<pubDate>Wed, 08 Oct 2008 13:50:51 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Free code]]></category>
		<category><![CDATA[Object pool]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/object-pool-class/</guid>
		<description><![CDATA[<p>Two of the slow operations in the flash player are object creation and garbage collection. If we pool objects - save objects when they're no longer needed and reuse them later when another object of the same type is required - then object creation is kept to a minimum and garbage collection is reduced to zero...</p>]]></description>
			<content:encoded><![CDATA[<p>Two of the slow operations in the flash player are object creation and garbage collection. If we pool objects &#8211; save objects when they&#8217;re no longer needed and reuse them later when another object of the same type is required &#8211; then object creation is kept to a minimum and garbage collection is reduced to zero.</p>

<p><a href="http://blog.joa-ebert.com/">Joa Ebert</a> discussed this in his presentation at <a href="http://www.flashonthebeach.com/">Flash on the Beach</a>. I already use specific object pooling in the <a href="http://flintparticles.org/">Flint particles library</a>, but while he was talking I had an idea and wrote a class for generic object pooling of all object types. I finally had time to test the class, and it works as expected, so I&#8217;ve added it to my <a href="http://code.google.com/p/bigroom/">open code repository</a>, where you can <a href="http://bigroom.googlecode.com/files/ObjectPool.zip">download it</a>.</p>

<p>The object pool class manages pooling of all objects through two simple methods. You can obtain an object from it like this</p>

<pre class="code">var obj:SomeClass = ObjectPool.getObject( SomeClass );</pre>

<p>If there are any such objects in the pool, one of them will be returned. If there are no such objects in the pool, a new one will be created and returned to you.</p>

<p>When you no longer need an object, you can add it to the pool for later reuse like this</p>

<pre class="code">ObjectPool.disposeObject( obj );</pre>

<p>The object doesn&#8217;t have to have been created through the pool &#8211; any object can be dropped into the pool with the disposeObject method.</p>

<p>The source code is available in <a href="http://code.google.com/p/bigroom/wiki/ObjectPool">my google code repository</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/object-pool-class/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Garbage Collection</title>
		<link>http://www.richardlord.net/blog/garbage-collection</link>
		<comments>http://www.richardlord.net/blog/garbage-collection#comments</comments>
		<pubDate>Tue, 12 Aug 2008 07:53:08 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Best practice]]></category>
		<category><![CDATA[Flint]]></category>
		<category><![CDATA[Garbage collection]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Particles]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/garbage-collection/</guid>
		<description><![CDATA[<p>I recently received a support query on Flint regarding garbage collection. In discussions on the forum I was reminded that many Actionscript developers don't know how the Flash Player's garbage collection works...</p>]]></description>
			<content:encoded><![CDATA[<p>I recently received a support query on <a href="http://flintparticles.org/">Flint</a> regarding garbage collection. In discussions on the <a href="http://flintparticles.org/forum">forum</a> I was reminded that many Actionscript developers don&#8217;t know how the Flash Player&#8217;s garbage collection works.</p>

<p>For some developers that&#8217;s not a problem since memory use is quite low on lots of web sites, and all the memory is freed when a user leaves the web site anyway. However, with the development of rich applications on the web and in Air, garbage collection is becoming an issue that more developers need to understand.</p>

<p>I was going to write a long post explaining garbage collection, but Grant Skinner got there two years before me. Here&#8217;s his useful series about <a href="http://gskinner.com/blog/archives/2006/06/as3_resource_ma.html">resource management in Flash</a>.</p>

<p>When you&#8217;ve read that, this more recent post by Sean Christmann adds further insight &#8211; <a href="http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/">Kick starting the garbage collector</a>.</p>

<p>Now there&#8217;s no excuse for leaving trash lying around.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/garbage-collection/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The parentheses operator</title>
		<link>http://www.richardlord.net/blog/the-parentheses-operator</link>
		<comments>http://www.richardlord.net/blog/the-parentheses-operator#comments</comments>
		<pubDate>Wed, 16 Jul 2008 08:10:57 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Event handlers]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/the-parentheses-operator/</guid>
		<description><![CDATA[<p>It's not uncommon for less experienced Actionscript developers, particularly self-taught developers, to be a little confused about the purpose of the parentheses you put after a function name when calling the function. The most common question is why aren't the parentheses used when assigning a function as an event handler?...</p>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not uncommon for less experienced Actionscript developers, particularly self-taught developers, to be a little confused about the purpose of the parentheses you put after a function name when calling the function. The most common question is why aren&#8217;t the parentheses used when assigning a function as an event handler? i.e. Why are there no parentheses after clickHandler in the first line of
this code?</p>

<pre class="code">addEventListener( MouseEvent.CLICK, clickHandler );

function clickHandler( event:MouseEvent ):void
{
	// function body here
}</pre>

<h3>What the documentation says</h3>

<p>The (usually excellent) Flash and Flex help isn&#8217;t much help here. In the Actionscript 3 language reference, it states that the parentheses &quot;Surrounds one or more parameters and passes them to the function that precedes the parentheses&quot;, which doesn&#8217;t explain why (or even if) the parentheses are necessary when no parameters are passed to the function.</p>

<p>Elsewhere in the help, it states that &quot;If you are calling a function with no parameters, you must use an empty pair of parentheses&quot;. No explanation &#8211; just do it. Which inevitably leads to developers wondering why they mustn&#8217;t do it when assigning event handlers.</p> 

<p>Colin Moock&#8217;s Essential Actionscript 3 (also usually excellent) takes a similar approach, simply stating &quot;Notice the important and mandatory use of the parentheses operator following the method name&quot;.</p>

<p>People learn things better if they understand them, so here&#8217;s my attempt at an explanation. If you&#8217;re confused about when to use the parentheses operator this should help. If not, come back tomorrow when I&#8217;ll post something a lot more advanced about programmatic skins in Flex.</p>

<h3>What the parentheses operator does</h3>

<p>A function is a portion of code that performs a specific task or set of tasks within your application. The function may be something you have defined, or it may be an intrinsic function (a function built-in to the flash player, like the trace function). When a function is a property of an object, it&#8217;s usually called a method. Here&#8217;s a trivial example function definition.</p>

<pre class="code">function sayHello():void
{
	someTextField.text = "Hello";
}</pre>

<p>The code inside the function is run by calling the function, like this.</p>

<pre class="code">sayHello();</pre>

<p>The parentheses could perhaps be better named as the function calling operator since that is what they do. We use the function&#8217;s name to refer to the function, and then we use the parentheses to run the function we have identified.</p>

<p>If the function needs some additional information in order to run (the parameters) then that information goes inside the parentheses.</p>

<pre class="code">function saySomething( thingToSay:String ):void
{
	someTextField.text = thingToSay;
}

saySomething( "This is a boring example" );</pre>

<p>But the parentheses, with or without parameters, are the operator that calls the function.</p>

<h3>What happens without the parentheses</h3>

<p>If that&#8217;s what the parentheses are for, what happens if we leave them out? Like this</p>

<pre class="code">sayHello;</pre>

<p>Well, first of all, you won&#8217;t get an error. sayHello exists (it&#8217;s defined above) so the code is valid. But, it doesn&#8217;t do anything. We have used the name of the function (&#8220;sayHello&#8221;) to refer to the function, then we&#8217;ve done nothing with it. When you put the parenthesis after the function you are indicating that you want to call the function now. Without the parenthesis, you&#8217;re not running the function. But calling a function is not the only thing we can do with it.</p>

<p>For example, we can assign it to a variable, like this</p>

<pre class="code">var myFunction:Function = sayHello;</pre>

<p>Now we can refer to the function via the variable. So if we used the parenthesis operator on the variable, it would call the function, like this</p>

<pre class="code">myFunction();</pre>

<p>Or we could continue to use it&#8217;s original name, like this</p>

<pre class="code">sayHello();</pre>

<h3>Event handlers</h3>

<p>When we set up an event handler, we don&#8217;t want to call the function straight away, we want the event handler to call the function later, when the event happens. So, we define an appropriate function</p>

<pre class="code">function clickHandler( event:MouseEvent ):void
{
	someTextField.text = "The mouse was clicked";
}</pre>

<p>Then we assign the function as a listener for the event</p>

<pre class="code">addEventListener( MouseEvent.CLICK, clickHandler );</pre>

<p>When we assign the function as a listener, we don&#8217;t want to call the function, so we don&#8217;t use the parentheses operator. Later, when the event actually happens, the flash player will call the function for us. There&#8217;s some code inside the EventDispatcher class that uses the parentheses operator to call the function when the event happens.</p>

<p>If you make the mistake of using the parentheses operator when assigning the event handler, like this</p>

<pre class="code">addEventListener( MouseEvent.CLICK, clickHandler() );</pre>

<p>then the event handler will be called immediately (you&#8217;ve told it to do so by using the parentheses). This will usually generate an error since you haven&#8217;t assigned a parameter for the event argument.</p>

<p>So that&#8217;s the parenthesis operator. Personally, I like the way that C++ names the parentheses operator the &quot;function operator&quot; &#8211; it&#8217;s the operator that calls a function.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/the-parentheses-operator/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 tetris source code</title>
		<link>http://www.richardlord.net/blog/actionscript-3-tetris-source-code</link>
		<comments>http://www.richardlord.net/blog/actionscript-3-tetris-source-code#comments</comments>
		<pubDate>Thu, 13 Dec 2007 11:35:13 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Free code]]></category>
		<category><![CDATA[Game development]]></category>
		<category><![CDATA[Tetris]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/actionscript-3-tetris-source-code/</guid>
		<description><![CDATA[This will certainly be useful to anyone wanting to make a tetris game. It's probably also useful to anyone learning Actionscript 3, particularly if they want to make games.

The <a href="http://flashgamecode.net/free/tetris-engine">source code</a> is on the <a href="http://flashgamecode.net/">Flash Game Code</a> web site. It's in two parts - an engine, which does the game part, and a sample game that uses the engine. Have fun.]]></description>
			<content:encoded><![CDATA[This will certainly be useful to anyone wanting to make a tetris game. It&#8217;s probably also useful to anyone learning Actionscript 3, particularly if they want to make games.

The <a href="http://code.google.com/p/bigroom/wiki/TetrisGameEngine">source code</a> is on my <a href="http://code.google.com/p/bigroom/">free code repository</a>. It&#8217;s in two parts &#8211; an engine, which does the game part, and a sample game that uses the engine. Have fun.]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/actionscript-3-tetris-source-code/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using uint as a loop iterator</title>
		<link>http://www.richardlord.net/blog/using-uint-as-a-loop-iterator</link>
		<comments>http://www.richardlord.net/blog/using-uint-as-a-loop-iterator#comments</comments>
		<pubDate>Wed, 21 Nov 2007 09:34:27 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/using-uint-as-a-loop-iterator/</guid>
		<description><![CDATA[<p>It took me some time to track down this bug in some code recently. I post it here to help others avoid the error. It's obvious once you see it...</p>]]></description>
			<content:encoded><![CDATA[<p>It took me some time to track down this bug in some code recently. I post it here to help others avoid the error. It&#8217;s obvious once you see it. When does this loop stop?</p>

<pre class="code">for( var i:uint = 5; i >= 0; i-- )
{
    // do something here
}</pre>

<p>The answer, of course, is never. The loop continues indefinitely because a uint can never be less than 0. Doh!</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/using-uint-as-a-loop-iterator/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Radial Perlin Noise</title>
		<link>http://www.richardlord.net/blog/radial-perlin-noise</link>
		<comments>http://www.richardlord.net/blog/radial-perlin-noise#comments</comments>
		<pubDate>Mon, 29 Oct 2007 14:00:34 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Free code]]></category>
		<category><![CDATA[Perlin noise]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/radial-perlin-noise/</guid>
		<description><![CDATA[<p>I was messing around with perlin noise, creating a radial effect for a game I'm working on. The result is a RadialPerlin class for creating radial perlin noise bitmaps. The code is licenced under the MIT license. Have fun, and if you make something interesting with it let me know.</p>]]></description>
			<content:encoded><![CDATA[<p>I have been messing around with perlin noise, creating a radial effect for a game I&#8217;m working on. The result is a RadialPerlin class for creating radial perlin noise bitmaps like this.</p><br />

<div class="spaced"><div id="swf4c5324692b8a3">
<p><b>Flash required:</b> You need version 9 or later of the free Flash player from Adobe to use this content. To download and install the free player from Adobe's web site <a href="http://get.adobe.com/flashplayer/">click here</a>.</p>
</div>
<script type="text/javascript">
var params = {loop:"false",quality:"high",allowfullscreen:"true"};
var flashvars = {};
swfobject.embedSWF("/images/blog/RadialPerlinDemo.swf", "swf4c5324692b8a3", "200", "200", "9.0.124", "/images/swf/expressInstall.swf", flashvars, params, {} );
</script></div>

<p>The code is in a single class called RadialPerlin, used like this</p>

<pre class="code">var perlin:RadialPerlin = new RadialPerlin( 100, 3, 
        Math.random() * 100000, false, 15, false, true );
perlin.draw( 0, 0 );
var bmp:Bitmap = new Bitmap( perlin.bitmapData );
addChild( bmp );</pre>

<p><a href="http://bigroom.googlecode.com/files/RadialPerlin.zip" title="Download source code">
<img src="/images/icons/asfile.gif" width="31" height="31" alt="Download source code" class="icon" />
<b>Download the RadialPerlin class and demo.</b></a></p>

<p>The RadialPerlin object is initialised with some values (details of the parameters are in the class file) then drawn into a BitmapData object using its draw method. The draw method takes a couple of offset parameters &#8211; one for the distance from the centre and the other for the rotation. You can then grab the BitmapData  object from the RadialPerlin object via its bitmapData property and do what you like with it.</p>

<p>The code is licenced under the MIT license. Have fun, and if you make something interesting with it let me know.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/radial-perlin-noise/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Keyboard polling class &#8211; bug fix</title>
		<link>http://www.richardlord.net/blog/keyboard-polling-class-bug-fix</link>
		<comments>http://www.richardlord.net/blog/keyboard-polling-class-bug-fix#comments</comments>
		<pubDate>Tue, 04 Sep 2007 07:53:07 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Free code]]></category>
		<category><![CDATA[Game development]]></category>
		<category><![CDATA[Keyboard polling]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/keyboard-polling-class-bug-fix/</guid>
		<description><![CDATA[There was an error in the Keyboard polling class that I posted yesterday. If you downloaded the class you&#8217;ll want the new version, which is available here.]]></description>
			<content:encoded><![CDATA[<p>There was an error in the Keyboard polling class that I <a href="/blog/polling-the-keyboard-in-actionscript-3">posted yesterday</a>. If you downloaded the class you&#8217;ll want the new version, <a href="http://code.google.com/p/bigroom/wiki/KeyPoll">which is available here</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/keyboard-polling-class-bug-fix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polling the keyboard in Actionscript 3</title>
		<link>http://www.richardlord.net/blog/polling-the-keyboard-in-actionscript-3</link>
		<comments>http://www.richardlord.net/blog/polling-the-keyboard-in-actionscript-3#comments</comments>
		<pubDate>Mon, 03 Sep 2007 17:36:35 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Free code]]></category>
		<category><![CDATA[Game development]]></category>
		<category><![CDATA[Keyboard polling]]></category>

		<guid isPermaLink="false">http://www.bigroom.co.uk/blog/polling-the-keyboard-in-actionscript-3/</guid>
		<description><![CDATA[<p>Games often need to get the current state of various keys in order to respond to user input. This is not the same as responding to key down and key up events, but is rather a case of discovering if a particular key is currently pressed.</p>

<p>In Actionscript 2 this was a simple matter of calling Key.isDown() with the appropriate key code. But in Actionscript 3 Key.isDown no longer exists and the only intrinsic way to react to the keyboard is via the key up and key down events. To rectify this I created the KeyPoll class...</p>]]></description>
			<content:encoded><![CDATA[<p>Games often need to get the current state of various keys in order to respond to user input. This is not the same as responding to key down and key up events, but is rather a case of discovering if a particular key is currently pressed.</p>

<p>In Actionscript 2 this was a simple matter of calling Key.isDown() with the appropriate key code. But in Actionscript 3 Key.isDown no longer exists and the only intrinsic way to react to the keyboard is via the key up and key down events.</p>

<p>To rectify this I created the KeyPoll class, which has isDown and isUp methods, each taking a key code as a parameter and returning a Boolean. The class and an example of its use are <a href="http://code.google.com/p/bigroom/wiki/KeyPoll">in my free code repository</a>.</p>

<p>The class uses a ByteArray to hold the current keyboard state, which is updated in response to Keyboard events and queried by the public methods, isDown and isUp. Using a ByteArray is more compact than using an Array of Booleans, and in tests it also turned out to be marginally faster, although the difference in speed was not significant enough to matter.</p>]]></content:encoded>
			<wfw:commentRss>http://www.richardlord.net/blog/polling-the-keyboard-in-actionscript-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
