<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Code Kills - ActionScript</title>
    <link>http://blog.codekills.net/</link>
    <description></description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:david@wolever.net" />
    <generator>Serendipity 1.1.3 - http://www.s9y.org/</generator>
    <pubDate>Wed, 10 Feb 2010 16:57:48 GMT</pubDate>

    <image>
        <url>http://blog.codekills.net/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Code Kills - ActionScript - </title>
        <link>http://blog.codekills.net/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>A Parameterized Testrunner for FlexUnit</title>
    <link>http://blog.codekills.net/archives/79-A-Parameterized-Testrunner-for-FlexUnit.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/79-A-Parameterized-Testrunner-for-FlexUnit.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=79</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=79</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;A couple of days ago, I &lt;a href=&quot;http://blog.codekills.net/archives/77-FlexUnits-Test-Theories-Dont-Bother.html&quot;&gt;complained about FlexUnit&#039;s Theories&lt;/a&gt;. Well, with a bit of encouragement from &lt;a href=&quot;http://twitter.com/drewbourne&quot;&gt;@drewbourne&lt;/a&gt;, I broke down and wrote a proper parameterized testrunner:&lt;/p&gt;

&lt;pre style=&quot;margin-top: -1.5em&quot;&gt;&lt;code&gt;
    [RunWith(&quot;utils.testrunners.ParameterizedRunner&quot;)]
    class AdditionTests {
        public static var numbersToTest:Array = [
            [1, 2, 3],
            [4, 5, 9],
            [-1, 1, 0]
        };

        [Parameterized(&quot;numbersToTest&quot;)]
        public function testAddition(a:int, b:int, expected:int):void {
            assertEqual(a+b, expected);
        }
    }
&lt;/pre&gt;

&lt;p&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that code will do exactly what you&#039;d expect: run three test cases, one for each of the inputs. If one test fails, the others will still run. Helpful error messages will be provided when a test fails.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;source can be downloaded&lt;/strong&gt; from: &lt;a href=&quot;http://gist.github.com/299871&quot;&gt;http://gist.github.com/299871&lt;/a&gt; &lt;small&gt;(and it will be getting a new home when ever I get around to releasing all of my AS utilities)&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Look useful? Give it a try and tell me what you think – I&#039;d love to know.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Wed, 10 Feb 2010 10:54:08 -0500</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/79-guid.html</guid>
    
</item>
<item>
    <title>FlexUnit's Test Theories: Don't Bother</title>
    <link>http://blog.codekills.net/archives/77-FlexUnits-Test-Theories-Dont-Bother.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/77-FlexUnits-Test-Theories-Dont-Bother.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=77</wfw:comment>

    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=77</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;I&#039;ve just been playing around with FlexUnit 4&#039;s nifty new &quot;Test Theories&quot;… And I have come to the conclusion that, right now, they are basically worthless.&lt;/p&gt;

&lt;p&gt;Here&#039;s why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They aren&#039;t documented. At all. There are approximately two examples on the internet, and the &lt;a href=&quot;http://docs.flexunit.org/index.php?title=Theory&quot;&gt;wiki page&lt;/a&gt; is a joke. Nothing explains what algorithm is used to calculate which &lt;a href=&quot;http://docs.flexunit.org/index.php?title=DataPoint&quot;&gt;DataPoints&lt;/a&gt; are applied to which theories.&lt;/li&gt;
&lt;li&gt;They make test error messages &lt;em&gt;less&lt;/em&gt; helpful. If a a theory fails, instead of getting a helpful error message like &quot;&lt;tt&gt;Theory `checkUrl(&quot;this is a bad url&quot;)` failed with message: could not determine protocol&lt;/tt&gt;&quot;, it gives a message like this: &quot;&lt;tt&gt;checkUrl urls[1]&lt;/tt&gt;&quot;. Yea, thanks guys.&lt;/li&gt;
&lt;li&gt;They don&#039;t do anything &quot;cool&quot;. At all. It would be cool if, given five data points, five distinct tests would be generated. It would be cool if one data point could fail while others succeed. Heck, anything which would make them better than a &lt;tt&gt;for&lt;/tt&gt; loop would be cool. But, alas…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, don&#039;t waste your time on Theories just yet. For now, just use a &lt;code&gt;for&lt;/code&gt; loop:&lt;/p&gt;

&lt;pre style=&quot;margin-left: 3em; margin-top: -1em; margin-bottom: 1em&quot;&gt;&lt;code&gt;
[Test]
public function runTestsOnData():void {
    for each (datum in testData)
        doSomeTest(datum);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or, if you want to test the &lt;a href=&quot;http://en.wikipedia.org/wiki/Cartesian_product&quot;&gt;cartesian product&lt;/a&gt; of a set of data, use &lt;a href=&quot;http://gist.github.com/296418&quot;&gt;my handy cartesian product function&lt;/a&gt;:&lt;/p&gt;

&lt;pre style=&quot;margin-left: 3em; margin-top: -1em; margin-bottom: 1em&quot;&gt;&lt;code&gt;
[Test]
public function runTestsOnCartesianProduct():void {
    for each (data in cartesian_product(testData0, testData1))
        doSomeTest.apply(this, data);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Followup&lt;/strong&gt;: as Alan (see comments) said, what I really want is a parameterized testrunner. So I&#039;ve gone ahead and written one. See &lt;a href=&quot;http://blog.codekills.net/archives/79-A-Parameterized-Testrunner-for-FlexUnit.html&quot;&gt;my post on a Parameterized Testrunner for FlexUnit&lt;/a&gt;.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Fri, 05 Feb 2010 18:47:58 -0500</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/77-guid.html</guid>
    
</item>
<item>
    <title>Best Ever Implementation of &quot;indexOf&quot;!</title>
    <link>http://blog.codekills.net/archives/69-Best-Ever-Implementation-of-indexOf!.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/69-Best-Ever-Implementation-of-indexOf!.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=69</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=69</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;(alternate title: &lt;em&gt;The &quot;Fail Early, Fail Often&quot; Principle in Action&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;I would like to award Adobe the &quot;best ever implementation of &lt;code&gt;indexOf&lt;/code&gt;&quot;. Ready for it? Here it is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;override flash_proxy function callProperty(name:*, ... rest):* {
    return null;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This beauty can be found in &lt;code&gt;mx.collections.ListCollectionView&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And the kicker? The function&#039;s documentation:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/**
 *  @private
 *  Any methods that can&#039;t be found on this class shouldn&#039;t be called,
 *  so return null
 */
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The author clearly knew that unknown methods* shouldn&#039;t be called… But instead of doing something sensible – like throwing an exception – they do something wholly nonsensical and return &lt;code&gt;null&lt;/code&gt;. Or, of course, they could also have left the function unimplemented, which would result in a strange and unhelpful exception… But, of course, I would expect nothing but the best from the Flex standard library.&lt;/p&gt;

&lt;p&gt;Next up: why implicit conversions from &lt;code&gt;null&lt;/code&gt; to &lt;code&gt;int&lt;/code&gt; are always wrong.&lt;/p&gt;

&lt;p&gt;&amp;lt;/rant&amp;gt;&lt;/p&gt;

&lt;p&gt;*: the magic &lt;code&gt;callProperty&lt;/code&gt; method is called on subclasses of &lt;code&gt;Proxy&lt;/code&gt; when a method can&#039;t be found. For example if &lt;code&gt;bar&lt;/code&gt; is not a method of &lt;code&gt;foo&lt;/code&gt;, executing &lt;code&gt;foo.bar()&lt;/code&gt;will call &lt;code&gt;foo.callProperty(&quot;bar&quot;)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;PS: Instead of calling &lt;code&gt;indexOf&lt;/code&gt;, I should have been calling &lt;code&gt;getItemIndex&lt;/code&gt;.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Mon, 07 Dec 2009 22:31:27 -0500</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/69-guid.html</guid>
    
</item>
<item>
    <title>Making Flex's PopUpMenuButton More Helpful</title>
    <link>http://blog.codekills.net/archives/58-Making-Flexs-PopUpMenuButton-More-Helpful.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/58-Making-Flexs-PopUpMenuButton-More-Helpful.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=58</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=58</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;If you&#039;re anything like me, you cringe every time you think about implementing a popup menu in Flex: the options, &lt;code&gt;PopUpButton&lt;/code&gt; and &lt;code&gt;PopUpMenuButton&lt;/code&gt;, are both terrible.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;PopUpButton&lt;/code&gt; makes you jump through the hoops of creating a &lt;code&gt;Menu&lt;/code&gt; and &lt;code&gt;PopUpMenuButton&lt;/code&gt; forces you to create an event handler just to get the currently selected item.&lt;/p&gt;

&lt;p&gt;Well, cringe no more! I&#039;ve done a bit of hacking on the &lt;code&gt;PopUpMenuButton&lt;/code&gt; to make the most common use-case, &quot;showing a list of options&quot;, a little bit less painful by adding a &#039;selectedItem&#039; field:&lt;/p&gt;

&lt;pre style=&#039;color:#000000;&#039;&gt;    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;XML&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;id&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;colors&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;
        &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;colors&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;
            &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;color&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;name&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;Red&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;rgb&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;0xFF0000&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;
            &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;color&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;name&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;Green&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;rgb&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;0x00FF00&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;
            &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;color&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;name&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;Blue&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;rgb&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;0x0000FF&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;
        &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;colors&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;
    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;XML&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;
    
    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;HelpfulPopupMenu&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;id&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;colorMenu&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;dataProvider&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;{colors}&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;labelField&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;@name&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;showRoot&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;false&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;

    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;Label&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;color&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;{XML(colorMenu.selectedItem).@rgb}&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;text&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;You&#039;ve chosen: {XML(colorMenu.selectedItem).@name}&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Which can also be used to set a temporary default option:&lt;/p&gt;

&lt;pre style=&#039;color:#000000;&#039;&gt;    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;Script&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;&lt;span style=&#039;color:#606060; &#039;&gt;&amp;lt;![CDATA[&lt;/span&gt;
        var people:Array = [
            { name: &quot;Bob&quot;, age: 16 },
            { name: &quot;Alice&quot;, age: 42 },
            { name: &quot;Jo&quot;, age: 31 }
        ];
        
    &lt;span style=&#039;color:#606060; &#039;&gt;]]&amp;gt;&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;Script&lt;/span&gt;&lt;span style=&#039;color:#a65700; &#039;&gt;&gt;&lt;/span&gt;
    
    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;HelpfulPopupMenu&lt;/span&gt; &lt;span style=&#039;color:#274796; &#039;&gt;id&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;peopleMenu&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;dataProvider&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;{people}&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;labelField&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;name&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;selectedItem&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;{ { name: &#039;(select a person)&#039;, age: null } }&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;showRoot&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;false&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;

    &lt;span style=&#039;color:#a65700; &#039;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#039;color:#666616; &#039;&gt;mx&lt;/span&gt;&lt;span style=&#039;color:#800080; &#039;&gt;:&lt;/span&gt;&lt;span style=&#039;color:#5f5035; &#039;&gt;Label&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;visible&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;{ peopleMenu.selectedItem.age !== null }&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;
        &lt;span style=&#039;color:#274796; &#039;&gt;text&lt;/span&gt;&lt;span style=&#039;color:#808030; &#039;&gt;=&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;That person is { peopleMenu.selectedItem.age } years old.&lt;/span&gt;&lt;span style=&#039;color:#0000e6; &#039;&gt;&quot;&lt;/span&gt; &lt;span style=&#039;color:#a65700; &#039;&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Useful? I&#039;d like to hope so.&lt;/p&gt;

&lt;p&gt;You can see a demo by clicking the image below (sorry, I don&#039;t actually know the first thing about embedding SWFs into HTML, and I don&#039;t feel up to learning right now):&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://wolever.net/~wolever/HelpfulPopupMenu/example/&quot;&gt;&lt;img src=&quot;http://img.skitch.com/20090825-g69br4c43ebm3a2ut7mudf7pik.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you can download the source (which is MIT licensed) from more or less the same place: &lt;a href=&quot;http://wolever.net/~wolever/HelpfulPopupMenu/&quot;&gt;http://wolever.net/~wolever/HelpfulPopupMenu/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, this is a small part of a larger library of helpful ActionScript utilities which I&#039;m going to be releasing… At some point.&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Tue, 25 Aug 2009 18:09:25 -0400</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/58-guid.html</guid>
    
</item>
<item>
    <title>Using Hamcrest to Filter ArrayCollections </title>
    <link>http://blog.codekills.net/archives/57-Using-Hamcrest-to-Filter-ArrayCollections.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/57-Using-Hamcrest-to-Filter-ArrayCollections.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=57</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=57</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;&lt;a href=&quot;http://twitter.com/nwebb&quot;&gt;Neil Webb&#039;s&lt;/a&gt; post on &lt;a href=&quot;http://nwebb.co.uk/blog/?p=371&quot;&gt;filtering an ArrayCollection on multiple property/values&lt;/a&gt; reminded me of how I recently solved exactly the same problem using &lt;a href=&quot;http://github.com/drewbourne/hamcrest-as3/tree/master&quot;&gt;Hamcrest-AS3&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, you know the story: you&#039;ve got an &lt;code&gt;ArrayCollection&lt;/code&gt; that&#039;s full of, say, &lt;code&gt;Laptop&lt;/code&gt;s, and you want to filter it by, say, price, size and (of course) color.&lt;/p&gt;

&lt;p&gt;Because you&#039;re a good programmer you always try to &lt;a href=&quot;http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html&quot;&gt;do the simplest thing that could possibly work&lt;/a&gt; first, and end up with a function something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function laptopFilter(laptop:Laptop):Boolean {
    if (laptop.price &amp;gt; appliedFilters.maxPrice)
        return false;

    if (laptop.size &amp;gt; appliedFilters.maxSize)
        return false;

    if (laptop.color != appliedFilters.preferredColor)
        return false;

    return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cool - that defiantly works, and it&#039;s pretty simple.&lt;/p&gt;

&lt;p&gt;&quot;But wait a second&quot;, you&#039;re thinking, &quot;what happens when the rules get more complex? That function is quickly going to loose its simplicity!&quot;&lt;/p&gt;

&lt;p&gt;Enter, &lt;a href=&quot;http://code.google.com/p/hamcrest/&quot;&gt;Hamcrest&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hamcrest is a library of &quot;matchers&quot; which are often used to build unit tests. Here is a quick example of a unit test written with Hamcrest:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[Test]
function testApplePicker():void {
    var apples:Array = ApplePicker.pick(&quot;granny smith&quot;);
    assertThat(apples.length, greaterThan(4));
    assertThat(apples, everyItem(hasPropery(&quot;color&quot;, &quot;green&quot;)));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But, of course, there is no reason that these same matchers shouldn&#039;t be used for other things too.&lt;/p&gt;

&lt;p&gt;Other things like, say, filtering an ArrayCollection:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var filters:Array = [
    hasProperty(&quot;price&quot;, greaterThan(1000)),
    hasProperty(&quot;color&quot;, either(&quot;red&quot;).or(&quot;blue&quot;).or(&quot;green&quot;)),
    hasProperty(&quot;size&quot;, between(10, 15))
];

var laptopFilter(laptop:Laptop):Boolean {
    return allOf.apply(null, filters).match(laptop);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, I&#039;ve hard-coded the values in this example, but it doesn&#039;t take much creativity to imagine how they could be dynamically generated, keeping the code nice and simple while still allowing for complex rules.&lt;/p&gt;

&lt;p&gt;So, that&#039;s how I filter ArrayCollections &lt;img src=&quot;http://blog.codekills.net/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;/p&gt;
 
    </content:encoded>

    <pubDate>Tue, 11 Aug 2009 12:03:38 -0400</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/57-guid.html</guid>
    
</item>
<item>
    <title>Overriding private methods in ActionScript, the hard way</title>
    <link>http://blog.codekills.net/archives/56-Overriding-private-methods-in-ActionScript,-the-hard-way.html</link>
            <category>ActionScript</category>
    
    <comments>http://blog.codekills.net/archives/56-Overriding-private-methods-in-ActionScript,-the-hard-way.html#comments</comments>
    <wfw:comment>http://blog.codekills.net/wfwcomment.php?cid=56</wfw:comment>

    <slash:comments>5</slash:comments>
    <wfw:commentRss>http://blog.codekills.net/rss.php?version=2.0&amp;type=comments&amp;cid=56</wfw:commentRss>
    

    <author>david@wolever.net (David Wolever)</author>
    <content:encoded>
    &lt;p&gt;Are you working with a proprietary &lt;code&gt;.swc&lt;/code&gt;? Does it have lots of bugs? Did the authors, in all their infinite wisdom, decide to hide those bugs in &lt;code&gt;private&lt;/code&gt; methods, so you stand no chance of being able to fix them?  Well, friend, let me show you how to fix that.&lt;/p&gt;
 &lt;br /&gt;&lt;a href=&quot;http://blog.codekills.net/archives/56-Overriding-private-methods-in-ActionScript,-the-hard-way.html#extended&quot;&gt;Continue reading &quot;Overriding private methods in ActionScript, the hard way&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 10 Jul 2009 10:49:49 -0400</pubDate>
    <guid isPermaLink="false">http://blog.codekills.net/archives/56-guid.html</guid>
    
</item>

</channel>
</rss>