<?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>GravityBlast &#187; RIA</title>
	<atom:link href="http://gravityblast.com/category/ria/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravityblast.com</link>
	<description>...coding blast beat!</description>
	<lastBuildDate>Tue, 14 Feb 2012 13:30:08 +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>Flex functional testing with FunFx and Cucumber</title>
		<link>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/</link>
		<comments>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 13:11:56 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=317</guid>
		<description><![CDATA[Cucumber is a great tool I usually use for BDD in my ruby projects, but yesterday I tried it with Flex, and it was very enjoyable. Here a little example on how to test Flex applications with Cucumber. First of all you need ruby, then you need to install the following gems: sudo gem install [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cukes.info/">Cucumber</a> is a great tool I usually use for <a href="http://en.wikipedia.org/wiki/Behavior_driven_development" title="Behavior Driven Development">BDD</a> in my ruby projects, but yesterday I tried it with Flex, and it was very enjoyable. Here a little example on how to test Flex applications with Cucumber.</p>
<p>First of all you need ruby, then you need to install the following gems:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rspec cucumber watir safariwatir funfx</pre></div></div>

<p>(I used the following codes on <strong>mac os x</strong>, with <strong>ruby 1.8.6</strong>, <strong>safari 4.0.3</strong> and <strong>funx 0.2.2</strong>)</p>
<p>After that open Flex Builder and create a new project called CucumberExample and use the following code for your main mxml file:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> id=<span style="color: #990000;">&quot;index&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;white&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>			
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrement&quot;</span> label=<span style="color: #990000;">&quot;-&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrement&quot;</span> label=<span style="color: #990000;">&quot;+&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;myLabel&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{index}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>As you can see, we have a number, 2 buttons and a label. Now create a directory called features inside your flex project folder and create the first Cucumber feature file, called counter:</p>
<p><strong>CucumberExample/features/counter.feature</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="cucumber" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">Feature</span>: Counter
  <span style="color:#9966CC; font-weight:bold;">In order</span> to count something
  As a flex rock star
  I want to use my great flex app
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">Scenario</span>: Increment index
    <span style="color:#9966CC; font-weight:bold;">Given</span> I open my flex app
    <span style="color:#9966CC; font-weight:bold;">And</span> I click the increment button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;1&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I click the decrement button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;0&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">When</span> I click the decrement button
    <span style="color:#9966CC; font-weight:bold;">Then</span> the label text should be <span style="color:#996600;">&quot;-1&quot;</span></pre></div></div>

<p>It&#8217;s a test written in pure plain text.</p>
<p>In the <strong>features</strong> folder create another folder called <strong>step_definitions</strong> with a blank file called <strong>counter_steps.rb</strong>, we&#8217;ll use it later.</p>
<p>Now open the console, go the to flex project root and run your test:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>CucumberExample
cucumber features</pre></div></div>

<p>You should see something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">7</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">7</span> undefined<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m0.002s</pre></div></div>

<p>You can implement step definitions for undefined steps with these snippets:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Given <span style="color:#006600; font-weight:bold;">/</span>^I <span style="color:#CC0066; font-weight:bold;">open</span> my flex app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I click the increment button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the label text should be <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>arg1<span style="color:#006600; font-weight:bold;">|</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I click the decrement button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  pending
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Before implementing the steps above, we need to add the funfx component to our library.</p>
<p>Download the latest <strong>swc</strong> file from <a href="http://rubyforge.org/frs/?group_id=3898&#038;release_id=16452">rubyforge</a> and place it in your <strong>CucumberExample/libs</strong> folder (I used the version 0.2.2).</p>
<p>Duplicate the bin-debug folder and rename it to <strong>test</strong> (you have a bin-debug folder after the first time you run the CucumberExample from FlexBuilder).</p>
<p>Inside the test directory create a file called <strong>test_server.rb</strong> with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'webrick'</span>
&nbsp;
server = <span style="color:#6666ff; font-weight:bold;">WEBrick::HTTPServer</span>.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:Port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">9852</span>, <span style="color:#ff3333; font-weight:bold;">:DocumentRoot</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;INT&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> server.<span style="color:#9900CC;">shutdown</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
server.<span style="color:#9900CC;">start</span></pre></div></div>

<p>Now you need a compiled version of your project that includes funfx.We&#8217;ll use it just for testing:</p>
<p><strong>build_test.sh</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">FLEX_SDK_HOME</span>=<span style="color: #ff0000;">&quot;/Applications/Adobe Flex Builder 3/sdks/3.2.0&quot;</span>
<span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/bin/mxmlc&quot;</span> <span style="color: #660033;">-verbose-stacktraces</span> <span style="color: #660033;">-include-libraries</span> .<span style="color: #000000; font-weight: bold;">/</span>libs<span style="color: #000000; font-weight: bold;">/</span>funfx-0.2.2.swc <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation.swc&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation_dmv.swc&quot;</span>  <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FLEX_SDK_HOME</span>/frameworks/libs/automation_agent.swc&quot;</span> <span style="color: #660033;">-output</span> .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>CucumberExample.swf <span style="color: #660033;">--</span> .<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>CucumberExample.mxml</pre></div></div>

<p>Run test <strong>compile_test.sh</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> .<span style="color: #000000; font-weight: bold;">/</span>build_test.sh
.<span style="color: #000000; font-weight: bold;">/</span>build_test.sh</pre></div></div>

<p>Now open another terminal window and start the test server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>CucumberExample<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
ruby test_server.rb</pre></div></div>

<p>Open http://localhost:9852/CucumberExample.html with your browser and you should see your flex app.</p>
<p>Now you can come back to your features and implement the step we leave before. Here my implementation:</p>
<p><strong>CucumberExample/features/step_definitions/counter_steps.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Given <span style="color:#006600; font-weight:bold;">/</span>^I <span style="color:#CC0066; font-weight:bold;">open</span> my flex app$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  open_flex_app
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Given <span style="color:#006600; font-weight:bold;">/</span>^I click the <span style="color:#006600; font-weight:bold;">&#40;</span>increment<span style="color:#006600; font-weight:bold;">|</span>decrement<span style="color:#006600; font-weight:bold;">&#41;</span> button$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>button<span style="color:#006600; font-weight:bold;">|</span>  
  click_button<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;button#{button.capitalize}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^the label text should be <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>text<span style="color:#006600; font-weight:bold;">|</span>
  label_text.<span style="color:#9900CC;">should</span> == text  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>open_flex_app</strong>, <strong>click_button</strong> and <strong>label_text</strong> are methods  defined in my <strong>env.rb</strong> file.</p>
<p><strong>CucumberExample/features/support/env.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;rubygems&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'funfx/browser/safariwatir'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> FlexWorld
  <span style="color:#9966CC; font-weight:bold;">def</span> open_flex_app
    <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://localhost:9852/CucumberExample.html&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> click_button<span style="color:#006600; font-weight:bold;">&#40;</span>button_id<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@flex_app</span>.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> button_id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> label_text
    <span style="color:#0066ff; font-weight:bold;">@flex_app</span>.<span style="color:#9900CC;">label</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;myLabel&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">text</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Before <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@browser</span>  = <span style="color:#6666ff; font-weight:bold;">Watir::Safari</span>.<span style="color:#9900CC;">new</span>
  <span style="color:#0066ff; font-weight:bold;">@flex_app</span> = <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">flex_app</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;CucumberExample&quot;</span>, <span style="color:#996600;">&quot;CucumberExample&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
After <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#0066ff; font-weight:bold;">@browser</span>.<span style="color:#9900CC;">close</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
World<span style="color:#006600; font-weight:bold;">&#40;</span>FlexWorld<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now you are ready to run your tests.  Start the test_server and then the features. You should have  an error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Then the label text should be <span style="color: #ff0000;">&quot;1&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
      expected: <span style="color: #ff0000;">&quot;1&quot;</span>,
           got: <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>using ==<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>This because we didn&#8217;t implement the functionality yet in our flex app. So, change the mxml file with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> id=<span style="color: #990000;">&quot;index&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;white&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>			
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrement&quot;</span> label=<span style="color: #990000;">&quot;-&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;index--&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrement&quot;</span> label=<span style="color: #990000;">&quot;+&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;index++&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #990000;">&quot;center&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;myLabel&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{index}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
		<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>HBox<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>VBox<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>It&#8217;s the same code but I added the click action to the increment and decrement buttons. Now compile the new code and run the features again:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build_test.sh
cucumber features</pre></div></div>

<p>You shoiuld have the following output, with all the seven steps passed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Feature: Counter
  In order to count something
  As a <span style="color: #c20cb9; font-weight: bold;">flex</span> rock star
  I want to use my great <span style="color: #c20cb9; font-weight: bold;">flex</span> app
&nbsp;
  Scenario: Increment index            <span style="color: #666666; font-style: italic;"># features/counter.feature:6</span>
    Given I open my <span style="color: #c20cb9; font-weight: bold;">flex</span> app           <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:1</span>
    And I click the increment button   <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;1&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
    When I click the decrement button  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;0&quot;</span>  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
    When I click the decrement button  <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:5</span>
    Then the label text should be <span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #666666; font-style: italic;"># features/step_definitions/counter_steps.rb:9</span>
&nbsp;
<span style="color: #000000;">1</span> scenario <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> passed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">7</span> steps <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">7</span> passed<span style="color: #7a0874; font-weight: bold;">&#41;</span>
0m9.781s</pre></div></div>

<p>If you have any problems you may want to clear the cache from safari.</p>
<p>I used the funfx gem from  <a href="http://funfx.rubyforge.org/">rubyforge</a> but it&#8217;s not up to date. If you want you can get the new code from <a href="http://github.com/peternic/funfx/tree/master">github</a>, it should have new features.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;submitHeadline=Flex+functional+testing+with+FunFx+and+Cucumber&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Flex+functional+testing+with+FunFx+and+Cucumber&amp;url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;T=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;title=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Flex+functional+testing+with+FunFx+and+Cucumber+@+http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/&amp;t=Flex+functional+testing+with+FunFx+and+Cucumber" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/08/20/flex-functional-testing-with-funfx-and-cucumber/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Mask problem with flex canvas and drag &amp; drop</title>
		<link>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/</link>
		<comments>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 23:34:37 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=170</guid>
		<description><![CDATA[Some weeks ago a spent a lot of time trying to fix a bug inside an AIR application I was working on. I wrote a custom component that has an image as child. This image is draggable, and the container should act as a mask. The problem was that when I started dragging the picture, [...]]]></description>
			<content:encoded><![CDATA[<p>Some weeks ago a spent a lot of time trying to fix a bug inside an AIR application I was working on.<br />
I wrote a custom component that has an image as child. This image is draggable, and the container should act as a mask. The problem was that when I started dragging the picture, the picture went outside its container, like the following example. </p>
<p>Try dragging the red square outside the white one:</p>
<p>
<object width="500" height="300">
<param name="movie" value="/wp-content/uploads/2009/07/dragdropcanvas1.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="300" src="/wp-content/uploads/2009/07/dragdropcanvas1.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>I fixed this bug just setting the scrollRect property to the container:</p>
<p>
<object width="500" height="300">
<param name="movie" value="/wp-content/uploads/2009/07/dragdropcanvas2.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="500" height="300" src="/wp-content/uploads/2009/07/dragdropcanvas2.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>Only when I realized how to fix the bug I found <a href="http://www.alterlogic.co.uk/blog/2009/1/20/flex-component-clipcontent-problems-and-mask-gotchas.html">another guy</a> with the same problem and the same solution.</p>
<p>Here the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<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>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
  layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span>
  applicationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>												
      <span style="color: #0066CC;">public</span> <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: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #006600;">scrollRect</span> = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">container</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;																
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseUpHandler</span><span style="color: #66cc66;">&#41;</span>;				
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">mouseDownHandler</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>			
&nbsp;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseDownHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
&nbsp;
      <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseUpHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">draggableCanvas</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</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><span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;container&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;white&quot;</span> horizontalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span> verticalScrollPolicy=<span style="color: #ff0000;">&quot;off&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;draggableCanvas&quot;</span> x=<span style="color: #ff0000;">&quot;50&quot;</span> y=<span style="color: #ff0000;">&quot;25&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#AA0000&quot;</span><span style="color: #66cc66;">&gt;</span>			
    <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
  <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;submitHeadline=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop&amp;url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;T=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;title=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop+@+http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/&amp;t=Mask+problem+with+flex+canvas+and+drag+%26%23038%3B+drop" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/12/mask-problem-with-flex-canvas-and-drag-drop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Speed up your sortable list with LiteSortable</title>
		<link>http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/</link>
		<comments>http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 16:32:24 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/</guid>
		<description><![CDATA[I love to use prototype and scriptaculous to create Rich Internet Application, and I love all the built-in effects and libraries of script.aculo.us. Today I was working with Sortable.create to provide a simple way to reorder images inside a gallery. I started using the same code used in the SortableListsDemo page of the official wiki. [...]]]></description>
			<content:encoded><![CDATA[<p>I love to use <a href="http://prototypejs.org/">prototype</a> and <a href="http://script.aculo.us/">scriptaculous</a> to create Rich Internet Application, and I love all the built-in effects and libraries of script.aculo.us.<br />
Today I was working with <a href="http://wiki.script.aculo.us/scriptaculous/show/Sortable.create">Sortable.create</a> to provide a simple way to reorder images inside a gallery. I started using the same code used in the <a href="http://wiki.script.aculo.us/scriptaculous/show/SortableListsDemo">SortableListsDemo</a> page of the official wiki. Each time the list is updated, the serialized list is sent to the server. The server receives the list and updates all the images positions. It&#8217;s pretty simple and works fine, but the problem is that the server executes a query for each image in the gallery. This means that if I have 100 images, 100 queries will be run. It&#8217;s a hell for my server! The best way to improve this action is to send to the server more detailed information, such as the dragged image, the old position and the new position. In this way I can execute only 2 queries for each movement. To do that I wrote a simple javascript class called LiteSortable that acts like the Sortable.create method. It receives the same parameters, and the same callbacks: onUpdate, onChange. The only change is that these 2 callbacks will receive more information about the movement, and I can improve the previous client side code with:</p>
<pre><code>function sort(list, element, id, old_position, new_position) {
  new Ajax.Request('/admin/gallery_item/sort/', {
    evalScripts:true,
    parameters: {
      id: id,
      old_position: old_position,
      new_position: new_position
    }
  });
}

document.observe('dom:loaded', function() {
  new LiteSortable('list', {
    onUpdate: sort
  });
});</code></pre>
<p>And the server code become like the following:</p>
<pre><code>def sort
  old_position, new_position = params[:old_position].to_i, params[:new_position].to_i
  @item = GalleryItem.find(:first, :conditions =&gt; ["id = ? AND position = ?", params[:id], old_position])
  if @item
    x, y, z = old_position &lt; new_position ? ["-", "&lt;", "&gt;"] : ["+", "&gt;", "&lt;"]
    GalleryItem.update_all("position = (position #{x} 1)", ["parent_id IS NULL AND gallery_id = ? AND position #{y}= ? AND position #{z}= ?", @item.gallery_id, new_position, old_position])
    @item.update_attribute('position', new_position)
  else
    @error = true
  end
end</code></pre>
<p>If @error is true, it means that the dragged image it&#8217;s been deleted or moved by somone else.<br />
If you want to use LiteSortable you can check out the entire project with:</p>
<pre><code>svn co http://dev.gravityblast.com/svn/projects/js/LiteSortable/</code></pre>
<p>&#8230;or save download the lite_sortable.js file from <a href="http://dev.gravityblast.com/svn/projects/js/LiteSortable/src/lite_sortable.js">here</a>.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;submitHeadline=Speed+up+your+sortable+list+with+LiteSortable&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Speed+up+your+sortable+list+with+LiteSortable&amp;url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;T=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;title=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Speed+up+your+sortable+list+with+LiteSortable+@+http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/&amp;t=Speed+up+your+sortable+list+with+LiteSortable" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2007/12/17/speed-up-your-sortable-list-with-litesortable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

