<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.36026-</id>
  <updated>2009-11-16T15:03:16Z</updated>
  <title>Comments for Building an Enterprise Framework - Enterprise Development with Flex, Part 1 (http://www.insideria.com/2009/05/chapter-preview-building-an-en.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.36026</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=36026" title="Building an Enterprise Framework - Enterprise Development with Flex, Part 1" />
    <published>2009-05-07T14:25:39Z</published>
    <updated>2009-05-13T13:58:07Z</updated>
    <title>Building an Enterprise Framework - Enterprise Development with Flex, Part 1</title>
    <summary>Note: This is excerpted from Chapter 3 of the Rough Cuts version of Enterprise Development with Flex. This book is still in progress, and you can get access to it now. Get the Enterprise Development with Flex Rough Cut Rough...</summary>
    <author>
      <name>Yakov Fain</name>
      
    </author>
    
    <category term="Features" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p><em>Note: This is excerpted from Chapter 3 of the <a href="http://oreilly.com/roughcuts/faq.csp" target="_blank">Rough Cuts</a> version of <a href="http://oreilly.com/catalog/9780596801014/">Enterprise Development with Flex</a>. This book is still in progress, and you can <a href="http://my.safaribooksonline.com/9780596801465?cid=orm-cat-readnow-9780596801465" target="_blank">get access to it now</a>.</em></p>

<div class="ap_r_front"><img src="http://oreilly.com/catalog/covers/9780596801014_cat.gif" alt="Enterprise Development with Flex cover" style="width: 148px;" /><div class="apcaption"><a href="http://oreilly.com/catalog/9780596801014/">Get the Enterprise Development with Flex Rough Cut</a></div></div>

<p><em><a href="http://www.oreilly.com/roughcuts">Rough Cuts</a> is a service from Safari Books Online that gives you early access to content on cutting-edge technologies -- before it's published.  It lets you literally read the book as it is being written. </em></p>

<h2 class="title"><a name="building_an_enterprise_framework" id=
"building_an_enterprise_framework"></a>Chapter&nbsp;3.&nbsp;Building
an Enterprise Framework</h2>

<p><b>Table of Contents, Part 1</b></p>
<p><a href=
"#introduction">Introduction</a></p>
<p><span class="sect1"><a href=
"#upgrading_existing_flex_components">Upgrading Existing
Flex Components</a></span></p>

<p><span class="sect2"><a href=
"#introducing_component_library_clear.swc">Introducing
Component Library clear.swc</a></span></p>
<p><span class="sect2"><a href=
"#creating_a_value-aware_checkbox">Creating a Value-Aware
CheckBox</a></span></p>
<p><span class="sect2"><a href=
"#creating_centered_checkbox">Creating Centered
CheckBox</a></span></p>
<p><span class="sect2"><a href=
"#creating_protected_checkbox">Creating Protected
CheckBox</a></span></p>
<p><span class="sect2"><a href=
"#upgrading_combobox">Upgrading ComboBox</a></span></p>
<p><span class="sect1"><a href=
"#resources_as_properties_of_ui_controls">Resources as
Properties of UI Controls</a></span></p>
<p><span class="sect2"><a href=
"#styles_vs._properties">Styles vs.
Properties</a></span></p>

<div class="epigraph">
<p><span class="emphasis"><em>Programming today is a race between
software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better
idiots. So far, the Universe is winning</em></span>.</p>
<div class="attribution"><span>--<span class=
"attribution"><span class="author"><span class=
"firstname">Rich</span> <span class=
"surname">Cook</span></span></span></span></div>
</div>

<div class="titlepage">
<div>
<div>
<h2 class="title"><a name="introduction" id=
"introduction"></a>Introduction</h2>
</div>
</div>
</div>
<p>There is no such thing as perfect design. Flex framework is
evolving, and we are grateful that software engineers from Flex
team made this framework extendable. Because this book covers the
use of Flex framework in enterprise software development, we will
identify and enhance those components that are widely used in
business RIA.</p>
<p>For the majority of the enterprise applications, development
comes down to a few major activities:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Creating data grids</p>
</li>
<li>
<p>Working with forms</p>
</li>
<li>
<p>Validating data</p>
</li>
<li>
<p>Printing</p>
</li>
</ul>
</div>
<p>If you, the architect, can achieve improvements in each of these
areas by automating common tasks, application developers will spend
less time writing the same mundane code over and over again. The
key is to encapsulate such code inside reusable Flex components, to
create smarter components that can be collected into libraries.</p>
<p>Chapter&nbsp;1, <i>Comparing Selected Flex Frameworks</i> reviewed such
architectural frameworks as Cairngorm, PureMVC and Mate, which
mainly helped with separating the code into tiers, but now you'll
learn how to build another type of a framework by enhancing
existing Flex components. Specifically, this chapter demonstrates
how to build a framework that radically simplifies creation of data
entry applications by:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Identifying common reusable components, which in turn reduces
the number of errors inevitably introduced during manual coding</p>
</li>
<li>
<p>Encapsulating implementation of architectural patterns inside
selected components</p>
</li>
<li>
<p>Defining best practices and implement them in concrete
components rather than just describing them on paper</p>
</li>
</ul>
</div>
<p>You'll learn how to inherit your components from the existing
ones, starting with the basic techniques while extending a simple
<code class="literal">CheckBox</code>, then approaching more
complex <code class="literal">ComboBox</code> component. The
remainder of the chapter is devoted to extending components that
every enterprise application relies on, namely <code class=
"literal">DataGrid</code>, <code class="literal">Form</code> and
<code class="literal">Validator</code>.</p>
<p>By providing a framework that integrates the work of
programmers, business analysts, designers, and advanced users, you
can drastically simplify the development of enterprise
applications.</p>
<p>Every Web developer is familiar with Cascading Style Sheets
(CSS) that allow designers define and change the look and feel of
the applications without the need to learn programming. As you'll
learn in this chapter, Business Style Sheets (BSS) serve a similar
role for enterprise application developers, enabling software
developers to attach a remote data set to a component with minimum
coding. For example, you'll see how a simple resource file can
instruct a <code class="literal">ComboBox</code> (or any other
component) where to get and how to display the data. Think of it as
a data skinning. With BSS you can develop artifacts that are highly
reusable across enterprise applications.</p>
<p>Along the way, you'll learn more about BSS and other techniques
for enhancing and automating Flex components. Although you won't be
able to build an entire framework here (the challenges of printing
and reporting are covered in the last chapter), you'll get a good
start in mastering valuable skills that any Flex architect and
component developer must have.</p>

<div class="titlepage">
<div>
<div>
<h2 class="title"><a name=
"upgrading_existing_flex_components" id=
"upgrading_existing_flex_components"></a>Upgrading Existing Flex
Components</h2>
</div>
</div>
</div>
<p>Flex evolved as Flash framework from HTML object model, and the
base set of Flex controls capitalized on simplicity of HTML. The
price that Flex developers have to pay for this is that each
control has its own (different) set of properties and behaviors.
This can make building an enterprise framework a challenge.
Consider a <code class="literal">CheckBox</code> control as an
example.</p>
<p>To quickly and easily integrate <code class=
"literal">CheckBox</code> into a variety of frameworks, developers
would prefer the component to have a unified property <span class=
"emphasis"><em>value</em></span> (<span class=
"emphasis"><em>on</em></span> or <span class=
"emphasis"><em>off</em></span> ) that's easily bindable to
application data. Currently, Flex's <code class=
"literal">CheckBox</code> has a property called <code class=
"literal">selected</code> and developers need to write code
converting <span class="emphasis"><em>Yes/No</em></span> the data
into the <code class="literal">true</code> or <code class=
"literal">false</code> that the <code class=
"literal">selected</code> property expects. If you later use
another control, you must then convert these <span class=
"emphasis"><em>Yes/No</em></span> values into the form that the new
control requires. Clearly some common ground would reduce the
amount of redundant coding.</p>
<p>The sections that follow will take a closer look at the
<code class="literal">CheckBox</code> as well as other major Flex
components that every application needs, identify what are they
missing, and how to enhance them.</p>

<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="introducing_component_library_clear.swc"
id="introducing_component_library_clear.swc"></a>Introducing
Component Library clear.swc</h3>
</div>
</div>
</div>
<p>As you may remember from Chapter&nbsp;1, <i>Comparing Selected Flex Frameworks</i>, Clear Toolkit's
component library, clear.swc, contains a number of enhanced Flex
components (<a href="#the_com.farata.components_pa" title=
"Figure&nbsp;3.1.&nbsp;The com.farata.components package from clear.swc">Figure&nbsp;3.1,
&ldquo;The com.farata.components package from
clear.swc&rdquo;</a>). Specifically, this component library
consists of three packages</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>com.farata.components</p>
</li>
<li>
<p>com.farata.grid</p>
</li>
<li>
<p>com.farata.printing</p>
</li>
</ul>
</div>
<p>To demonstrate how you can extend components, in the following
sections we'll explain how we built some of the components from the
package com.farata.component. Later you can use these discussions
for reference, if you decide to built a similar (or better) library
of components. (Some of the classes from the other two packages
will be discussed in Chapter 11 of this book.)</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>You can find the source code of all components described in this
chapter in the clear.swc component library. The code of some of the
components explained here was simplified to make explanations of
the process of extending Flex components easier. Neither this
chapter nor the book as a whole is meant to be a manual for the
open source clear.swc library. If you just want to use clear.swc
components, refer to <a href=
"https://sourceforge.net/projects/cleartoolkit/" target=
"_top">https://sourceforge.net/projects/cleartoolkit/</a> where the
asdoc-style API and the source code of each component from
clear.swc is available.</p>
</div>
<div class="figure"><a name="the_com.farata.components_pa" id=
"the_com.farata.components_pa"></a>
<p class="title"><b>Figure&nbsp;3.1.&nbsp;The com.farata.components
package from clear.swc</b></p>
<div class="figure-contents">
<div class="mediaobject"><a name="I_mediaobject3_d1e7606" id=
"I_mediaobject3_d1e7606"></a><img src="http://www.insideria.com/riaimages/edwf_0301.png" alt=
"The com.farata.components package from clear.swc" /></div>
</div>
</div>
<br class="figure-break" />
<p>You can use clear.swc independently by linking it to your Flex
project. To help you understand how its components can help you,
the following sections examine simplified versions of some of the
library's controls.</p>


<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="creating_a_value-aware_checkbox" id=
"creating_a_value-aware_checkbox"></a>Creating a Value-Aware
CheckBox</h3>
</div>
</div>
</div>
<p>The <code class="literal">CheckBox</code> in <a href=
"#checkbox_with_value_and_tex" title=
"Example&nbsp;3.1.&nbsp;CheckBox with value and text properties">Example&nbsp;3.1,
&ldquo;CheckBox with value and text properties&rdquo;</a> has been
enhanced with additional <code class="literal">value</code> and
<code class="literal">text</code> properties. You can specify which
value should trigger turning this control into the on/off
position.</p>
<div class="example"><a name="checkbox_with_value_and_tex" id=
"checkbox_with_value_and_tex"></a>
<p class="title"><b>Example&nbsp;3.1.&nbsp;CheckBox with value and
text properties</b></p>
<div class="example-contents">
 
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>package com.farata.controls {
     <span class="category1">import</span> flash.events.Event;
     <span class="category1">import</span> flash.events.KeyboardEvent;
     <span class="category1">import</span> flash.events.MouseEvent;
 
     <span class="category1">import</span> mx.controls.CheckBox;
     <span class="category1">import</span> mx.events.FlexEvent;
 
     <span class="category1">public</span> <span class="category1">class</span> CheckBox <span class="category1">extends</span> mx.controls.CheckBox {
  
            <span class="category1">public</span> <span class="category1">var</span> onValue:<span class="category2">Object</span>=<span class="category1">true</span>;
            <span class="category1">public</span> <span class="category1">var</span> offValue:<span class="category2">Object</span>=<span class="category1">false</span>;
            <span class="category1">private</span> <span class="category1">var</span> _value:*;
  
            <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> <span class="category2">text</span>(<span class="category2">o</span>:<span class="category2">Object</span>):<span class="category1">void</span> {
                  value = <span class="category2">o</span>;
             }
            <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> <span class="category2">text</span>():<span class="category2">Object</span> {
                  <span class="category1">return</span> value;
             }
  
          [Bindable("<span class="quote">valueCommit</span>")]
            <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> value(val:*) :<span class="category1">void</span> {
                  _value = val;
                  invalidateProperties();
                  dispatchEvent(<span class="category1">new</span> FlexEvent (FlexEvent.VALUE_COMMIT));
             }
  
            <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> value():<span class="category2">Object</span>  {
                <span class="category1">return</span> selected?onValue:offValue;
             }
  
            override protected <span class="category1">function</span> commitProperties():<span class="category1">void</span> {
                  <span class="category1">if</span> (_value!==<span class="category1">undefined</span>)
                        selected = (_value == onValue);
                  <span class="category1">super</span>.commitProperties();
             }
      }
}</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>This <code class="literal">CheckBox</code> will automatically
switch itself into a selected or unselected state: Just add it to
your view, set the on and off values, and either assign the
<code class="literal">String</code> or an <code class=
"literal">Object</code> value to it. Please note that the
<code class="literal">value</code> setter calls the function
<code class="literal">invalidateProperties()</code>, which
internally schedules the invocation of the function <code class=
"literal">commitProperties()</code> on the next UI refresh
cycle.</p>
<p>The <code class="literal">commitProperties()</code> function
enables you to make changes to all the properties of a component in
one shot. That's why we set the value of the selected property
based on the result of comparison of <code class=
"literal">_value</code> and <code class="literal">onValue</code> in
this function.</p>
<p><a href="#test_application_for_the_va" title=
"Example&nbsp;3.2.&nbsp;Test application for the value-aware CheckBox">
Example&nbsp;3.2, &ldquo;Test application for the value-aware
CheckBox&rdquo;</a> is a test application illustrating how to use
this <code class="literal">CheckBox with the</code> resulting
interface shown in <a href="#testing_the_value-aware_chec"
title=
"Figure&nbsp;3.2.&nbsp;Testing the value-aware CheckBox">Figure&nbsp;3.2,
&ldquo;Testing the value-aware CheckBox&rdquo;</a>. To run a test,
click the first Set OnValue= button to teach the <code class=
"literal">CheckBox</code> to turn itself <span class=
"emphasis"><em>on</em></span> when the value <span class=
"emphasis"><em>Male</em></span> is assigned, and <span class=
"emphasis"><em>off</em></span> when its property text has the value
of <span class="emphasis"><em>Female</em></span>. Then, click the
first or second cbx_test.text button to assign a value to the newly
introduced property text of this <code class=
"literal">CheckBox</code>, and watch how its state changes.</p>
<div class="example"><a name="test_application_for_the_va" id=
"test_application_for_the_va"></a>
<p class="title"><b>Example&nbsp;3.2.&nbsp;Test application for the
value-aware CheckBox</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:<span class="category2">Application</span> xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:<span class="category2">clear</span>="<span class="quote">com.farata.controls.*</span>" layout="<span class="quote">vertical</span>"&gt;

    &lt;<span class="category2">clear</span>:CheckBox id="<span class="quote">cbx_test</span>" <span class="category1">label</span>="<span class="quote">Assign me a value</span>" /&gt;

    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">Set OnValue='Male' and offValue='Female'</span>"
         click="<span class="quote">cbx_test.onValue='Male';cbx_test.offValue='Female';</span>"/&gt;

    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">cbx_test.text='Male'</span>" click="<span class="quote">cbx_test.text='Male'</span>" /&gt;
    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">cbx_test.text='Female'</span>" click="<span class="quote">cbx_test.text='Female'</span>" /&gt;

    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">Set OnValue=Number('1') and offValue=Number('0')</span>"
         click="<span class="quote">cbx_test.onValue=Number('1');cbx_test.offValue=Number('0');</span>"/&gt;

    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">cbx_test.value='Number('1')'</span>"
              click="<span class="quote">cbx_test.value =new Number('1')</span>" /&gt;
    &lt;mx:<span class="category2">Button</span> <span class="category1">label</span>="<span class="quote">cbx_test. value='Number('0')</span>"
              click="<span class="quote">cbx_test.value =new Number('0')</span>" /&gt;

&lt;/mx:<span class="category2">Application</span>&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<div class="figure"><a name="testing_the_value-aware_chec" id=
"testing_the_value-aware_chec"></a>
<p class="title"><b>Figure&nbsp;3.2.&nbsp;Testing the value-aware
CheckBox</b></p>
<div class="figure-contents">
<div class="mediaobject"><a name="I_mediaobject3_d1e7713" id=
"I_mediaobject3_d1e7713"></a><img src="http://www.insideria.com/riaimages/edwf_0302.png" alt=
"Testing the value-aware CheckBox" /></div>
</div>
</div>
<br class="figure-break" />

<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="creating_centered_checkbox" id=
"creating_centered_checkbox"></a>Creating Centered CheckBox</h3>
</div>
</div>
</div>
<p>This example demonstrates how to create a <code class=
"literal">CheckBox</code> that can center itself horizontally in
any container, including a data grid cell.</p>
<p>Although you could introduce an item renderer that uses a
<code class="literal">CheckBox</code> inside an <code class=
"literal">HBox</code> with the style <code class=
"literal">horizontalAlign</code> set to <code class=
"literal">center</code>, using a container inside the item rendered
negatively affect the data grid control's performance.</p>
<p>The better approach is to extend the styling of the <code class=
"literal">CheckBox</code> itself. Here is a code extension that
"teaches" a standard Flex <code class="literal">CheckBox</code> to
respond to the <code class="literal">textAlign</code> style if the
<code class="literal">label</code> property of the <code class=
"literal">CheckBox</code> is not defined:</p>
<div class="example"><a name="self-centering_solution_for" id=
"self-centering_solution_for"></a>
<p class="title"><b>Example&nbsp;3.3.&nbsp;Self-centering solution
for CheckBox</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>override protected <span class="category1">function</span> updateDisplayList(unscaledWidth:<span class="category2">Number</span>,
      unscaledHeight:<span class="category2">Number</span>):<span class="category1">void</span> {
 
     <span class="category1">super</span>.updateDisplayList(unscaledWidth, unscaledHeight);
     <span class="category1">if</span> (currentIcon) {
            <span class="category1">var</span> style:<span class="category2">String</span> = <span class="category2">getStyle</span>("<span class="quote">textAlign</span>");
            <span class="category1">if</span> ((!<span class="category1">label</span>) &amp;&amp; (style=="<span class="quote">center</span>") ) {
                  currentIcon.<span class="category2">x</span> = (unscaledWidth - currentIcon.measuredWidth)/2;
       }
                 }
           }</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>In the code above, the <code class="literal">x</code> coordinate
of the <code class="literal">CheckBox</code> icon will be always
located in the center of the enclosing container. Because no
additional container is introduced, you can use this approach in
the <code class="literal">DataGridColumn</code> item renderer,
which is a style selector. When you use this enhanced <code class=
"literal">CheckBox</code> as a column item renderer, <code class=
"literal">textAlign</code> automatically becomes a style of this
style selector, and you can simply set <code class=
"literal">textAlign=true</code> on <code class=
"literal">DataGridColumn</code>.</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>While developing enhanced components for the enterprise business
framework, concentrate on identifying reusable functionality that
application developers often need, program it once and incorporate
it in the component itself.</p>
</div>


<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="creating_protected_checkbox" id=
"creating_protected_checkbox"></a>Creating Protected CheckBox</h3>
</div>
</div>
</div>
<p>The standard Flex <code class="literal">CheckBox</code> has a
Boolean property called <code class="literal">enabled</code> that
is handy when you want to disable the control. Unfortunately,
disabled a <code class="literal">CheckBox</code> is rendered as
grayed out. What if you want to use a <code class=
"literal">CheckBox</code> in some non-editable container, say in a
<code class="literal">DataGridColumn</code> and you want it to be
non-updatable but look normal.</p>
<p>The answer is to use a new class called <code class=
"literal">CheckBoxProtected</code>, which includes an additional
property <code class="literal">updatable</code>. Its trick is to
suppress standard keyboard and mouse click processing. Overriding
event handlers by adding</p>
<p><code class="literal">if (!updateable) return;</code></p>
<p>works like charm! <a href="#class_checkboxprotected"
title=
"Example&nbsp;3.4.&nbsp;Class CheckBoxProtected">Example&nbsp;3.4,
&ldquo;Class CheckBoxProtected&rdquo;</a> lists the complete
code.</p>
<div class="example"><a name="class_checkboxprotected" id=
"class_checkboxprotected"></a>
<p class="title"><b>Example&nbsp;3.4.&nbsp;Class
CheckBoxProtected</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>package com.farata.controls
{
     <span class="category1">import</span> flash.events.Event;
     <span class="category1">import</span> flash.events.KeyboardEvent;
     <span class="category1">import</span> flash.events.MouseEvent;
     <span class="category1">import</span> mx.controls.CheckBox;
 
     <span class="category1">public</span> <span class="category1">class</span> CheckBoxProtected <span class="category1">extends</span> mx.controls.CheckBox {
  
      <span class="category1">public</span> <span class="category1">var</span> updateable:<span class="category2">Boolean</span> = <span class="category1">true</span>;
  
      <span class="category1">public</span> <span class="category1">function</span> CheckBoxProtected() {
             <span class="category1">super</span>();
             addEventListener(MouseEvent.CLICK, onClick);
       }
      <span class="category1">private</span> <span class="category1">function</span> onClick (event:MouseEvent):<span class="category1">void</span> {
             dispatchEvent(<span class="category1">new</span> Event(Event.CHANGE));
       }
      override protected <span class="category1">function</span> keyDownHandler(event:KeyboardEvent):<span class="category1">void</span> {
               <span class="category1">if</span> (!updateable) <span class="category1">return</span>;
               <span class="category1">super</span>.keyDownHandler(event);
       }
      override protected <span class="category1">function</span> keyUpHandler(event:KeyboardEvent):<span class="category1">void</span> {
               <span class="category1">if</span> (!updateable) <span class="category1">return</span>;
               <span class="category1">super</span>.keyUpHandler(event);
       }
      override protected <span class="category1">function</span> mouseDownHandler(event:MouseEvent):<span class="category1">void</span> {
             <span class="category1">if</span> (!updateable)<span class="category1">return</span>;
             <span class="category1">super</span>.mouseDownHandler(event);
       }
      override protected <span class="category1">function</span> mouseUpHandler(event:MouseEvent):<span class="category1">void</span> {
               <span class="category1">if</span> (!updateable)<span class="category1">return</span>;
               <span class="category1">super</span>.mouseUpHandler(event);
       }
      override protected <span class="category1">function</span> clickHandler(event:MouseEvent):<span class="category1">void</span> {
               <span class="category1">if</span> (!updateable)<span class="category1">return</span>;
               <span class="category1">super</span>.clickHandler(event);
           }
      }
}</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>To test the protected <code class="literal">CheckBox</code> use
<a href="#test_application_for_checkb" title=
"Example&nbsp;3.5.&nbsp;Test application for CheckBoxProtected">Example&nbsp;3.5,
&ldquo;Test application for CheckBoxProtected&rdquo;</a>.</p>
<div class="example"><a name="test_application_for_checkb" id=
"test_application_for_checkb"></a>
<p class="title"><b>Example&nbsp;3.5.&nbsp;Test application for
CheckBoxProtected</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:<span class="category2">Application</span> xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:<span class="category2">clear</span>="<span class="quote">com.farata.controls.*</span>" layout="<span class="quote">vertical</span>"&gt;

 &lt;<span class="category2">clear</span>:CheckBoxProtected updateable="<span class="quote">false</span>"
                <span class="category1">label</span>="<span class="quote">I am protected</span>" fontSize="<span class="quote">18</span>"/&gt;
 &lt;mx:CheckBox <span class="category2">enabled</span>="<span class="quote">false</span>"
                <span class="category1">label</span>="<span class="quote">I am disabled</span>" fontSize="<span class="quote">18</span>"/&gt;

&lt;/mx:<span class="category2">Application</span>&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>Running this application produces the results in <a href=
"#running_checkboxprotectedapp" title=
"Figure&nbsp;3.3.&nbsp;Running CheckBoxProtectedApp">Figure&nbsp;3.3,
&ldquo;Running CheckBoxProtectedApp&rdquo;</a>, which shows the
difference between the protected and disabled checkboxes.</p>
<div class="figure"><a name="running_checkboxprotectedapp" id=
"running_checkboxprotectedapp"></a>
<p class="title"><b>Figure&nbsp;3.3.&nbsp;Running
CheckBoxProtectedApp</b></p>
<div class="figure-contents">
<div class="mediaobject"><a name="I_mediaobject3_d1e7964" id=
"I_mediaobject3_d1e7964"></a><img src="http://www.insideria.com/riaimages/edwf_0303.png" alt=
"Running CheckBoxProtectedApp" /></div>
</div>
</div>
<br class="figure-break" />
<p>Why not use extensibility of Flex framework to its fullest? This
chapter is about what you <span class=
"emphasis"><em>can</em></span> do with Flex components. Armed with
this knowledge you'll make your own decisions about what do you
<span class="emphasis"><em>want</em></span> to do with them.</p>
<p>For example, think of a <code class="literal">CheckBox</code>
with a third state. The underlying data can be <span class=
"emphasis"><em>Yes</em></span>, <span class=
"emphasis"><em>No</em></span> and <code class=
"literal">null</code>. If the value is <code class=
"literal">null</code> (the third state), the <code class=
"literal">CheckBox</code> needs to display a different image, say a
little question mark inside. In addition to supporting three states
(selected, unselected and <code class="literal">null</code>) this
control should allow an easy switch from one state to another. Such
an enhancement includes a skinning task &ndash; create a new skin
(with a question mark) in Photoshop and ensure that the control
switches to this state based on the underlying data. For a working
example, see <code class="literal">CheckBox3Stated</code> in the
<span class="emphasis"><em>clear.swc</em></span> component
library.</p>


<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="upgrading_combobox" id=
"upgrading_combobox"></a>Upgrading ComboBox</h3>
</div>
</div>
</div>
<p>The <code class="literal">CheckBox</code> is easiest to enhance
because it's one of the simplest controls, having only two states
(<span class="emphasis"><em>on</em></span> or <span class=
"emphasis"><em>off)</em></span>. You can apply the same principles
to a more advanced <code class="literal">ComboBox</code>, however.
Identify reusable functionality, program it once, and incorporate
it into the component.</p>
<p>What if, for example, you need to programmatically request a
specific value to be selected in a <code class=
"literal">ComboBox</code>? The traditional approach is to write
code that loops through the list of items in the <code class=
"literal">ComboBox</code> data provider and manually work with the
<code class="literal">selectedIndex</code> property. To set
<span class="emphasis"><em>Texas</em></span> as a selected value of
a <code class="literal">ComboBox</code> that renders states, you
could use:</p>
<a name="I_programlisting3_d1e8042" id=
"I_programlisting3_d1e8042"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre><span class="category1">var</span> val:<span class="category2">String</span>; val= '<span class="quote">Texas</span>' ;
<span class="category1">for</span> (<span class="category1">var</span> i: <span class="category1">int</span> = 0; i &lt; cbx.dataProdider.<span class="category2">length</span>; i++) {
     <span class="category1">if</span> ( val == cbx_states.dataProvider[i].<span class="category1">label</span>) {
        cbx_states.selectedIndex = i;
        <span class="category1">break</span>;
    }
}</pre>
</code>

</div></div> 
<p>The downside of this approach is that if your application has
fifty <code class="literal">ComboBox</code> controls, several
developers will be writing similar loops instead of a single line,
such as <code class="literal">cbx_states.value="Texas"</code>.</p>
<p>Unfortunately, <code class="literal">ComboBox</code> does not
provide a specific property that contains the selected value. It
has such properties as <code class="literal">labelField</code>,
<code class="literal">selectedIndex</code>, and <code class=
"literal">selectedItem</code>. Which one of them is actually a data
field? How to search by value? Do you really care what's the number
of the selected row in the <code class="literal">ComboBox</code>?
Not at all you need to know the selected value.</p>
<p>Let's revisit the code snippet above. The <code class=
"literal">labelField</code> of a <code class=
"literal">ComboBox</code> knows the name of the property from the
objects stored in backing collection. But what about the data field
that corresponds to this label (say, in case of <code class=
"literal">Texas</code>, a good candidate to be considered as the
<code class="literal">ComboBox</code> data could be <code class=
"literal">TX</code>)? Currently, finding such data is a
responsibility of the application programmer.</p>
<p>Even if you are OK with writing these loops, considering an
asynchronous nature of populating data providers, this code may
need to wait until the data will arrive from the server. It would
be nice though if you could simply assign the value to a
<code class="literal">ComboBox</code> without the need to worry
about asynchronous flows of events.</p>
<p>Consider a <code class="literal">List</code> control, the
brother of the <code class="literal">ComboBox</code>. Say, the user
selected five items, and then decided to filter the backing data
collection. The user's selections will be lost. The <code class=
"literal">List</code> is also crying for another property that
remembers selected values and can be used without worrying about
the time of data arrival.</p>
<p><a href="#class_com.farata.control.co" title=
"Example&nbsp;3.6.&nbsp;Class com.farata.control.ComboBoxBase">Example&nbsp;3.6,
&ldquo;Class com.farata.control.ComboBoxBase&rdquo;</a> offers a
solution: The class <code class="literal">ComboBoxBase</code>,
which extends <code class="literal">ComboBox</code> by adding the
<code class="literal">value</code> property (don't confuse it with
<code class="literal"><mx:ComboBoxBase></code>). After
introducing the <code class="literal">value</code> property, it
uses the <code class="literal">dataField</code> property to tells
the <code class="literal">ComboBox</code> the name of the data
field in the object of its underlying data collection that
corresponds to this <code class="literal">value</code>. The new
<code class="literal">dataField</code> property enables you to use
any arbitrary object property as <code class=
"literal">ComboBox</code> data.</p>
<p>You'll also notice one more public property: <code class=
"literal">keyField</code>, which is technically a synonym of
<code class="literal">dataField</code>. You can use <code class=
"literal">keyField</code> to avoid naming conflicts in situations
where the <code class="literal">ComboBoxBase</code> or its
subclasses are used inside other objects (say <code class=
"literal">DataGridColumn</code>) that also have a property called
<code class="literal">dataField</code>.</p>
<div class="example"><a name="class_com.farata.control.co" id=
"class_com.farata.control.co"></a>
<p class="title"><b>Example&nbsp;3.6.&nbsp;Class
com.farata.control.ComboBoxBase</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>package com.farata.controls {
     <span class="category1">import</span> flash.events.Event;
 
     <span class="category1">import</span> mx.collections.CursorBookmark;
     <span class="category1">import</span> mx.collections.ICollectionView;
     <span class="category1">import</span> mx.collections.IViewCursor;
     <span class="category1">import</span> mx.controls.ComboBox;
     <span class="category1">import</span> mx.controls.dataGridClasses.DataGridListData;
     <span class="category1">import</span> mx.controls.listClasses.ListData;
     <span class="category1">import</span> mx.core.mx_internal;
     use namespace mx_internal;
 
     <span class="category1">public</span> <span class="category1">class</span> ComboBoxBase <span class="category1">extends</span> ComboBox {
  
      <span class="category1">public</span> <span class="category1">function</span> ComboBoxBase() {
        <span class="category1">super</span>();
        addEventListener("<span class="quote">change</span>", onChange);
       }
  
      <span class="linecomment">// Allow control to change dataProvider data on change</span>
      <span class="category1">private</span> <span class="category1">function</span> onChange(event:Event):<span class="category1">void</span> {
            <span class="category1">if</span> (listData is DataGridListData) {
                 <span class="category2">data</span>[DataGridListData(listData).dataField] = value;
             }<span class="category1">else</span> <span class="category1">if</span> (listData is ListData &amp;&amp; ListData(listData).labelField
    <span class="category1">in</span> <span class="category2">data</span>) {
                 <span class="category2">data</span>[ListData(listData).labelField] = value;
             }
       }
  
      protected <span class="category1">function</span> applyValue(value:<span class="category2">Object</span>):<span class="category1">void</span> {
          <span class="category1">if</span> ((value != <span class="category1">null</span>) &amp;&amp; (dataProvider != <span class="category1">null</span>)) {
              <span class="category1">var</span> cursor:IViewCursor = (dataProvider as
     ICollectionView).createCursor( );
                   <span class="category1">var</span> i:uint = 0;
                    <span class="category1">for</span> (cursor.<span class="category2">seek</span>( CursorBookmark.FIRST ); !cursor.afterLast;
                                                           cursor.moveNext(), i++) {
                         <span class="category1">var</span> entry:<span class="category2">Object</span> = cursor.current;
                         <span class="category1">if</span> ( !entry ) <span class="category1">continue</span>;
                         <span class="category1">if</span> ( (dataField <span class="category1">in</span> entry &amp;&amp; value == entry[dataField])) {
                              selectedIndex = i;
                              <span class="category1">return</span>;
                          }
                     }
                }
               selectedIndex = -1;
           }
  
      <span class="category1">private</span> <span class="category1">var</span> _dataField:<span class="category2">String</span> = "<span class="quote">data</span>";
      <span class="category1">private</span> <span class="category1">var</span> _dataFieldChanged:<span class="category2">Boolean</span> = <span class="category1">false</span>;
  
      [Bindable("<span class="quote">dataFieldChanged</span>")]
      [Inspectable(category="<span class="quote">Data</span>", defaultValue="<span class="quote">data</span>")]
  
      <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> dataField():<span class="category2">String</span> { <span class="category1">return</span> _dataField; }
      <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> dataField(value:<span class="category2">String</span>):<span class="category1">void</span> {
             <span class="category1">if</span> ( _dataField == value)
             <span class="category1">return</span>;
   
             _dataField = value;
             _dataFieldChanged = <span class="category1">true</span>;
             dispatchEvent(<span class="category1">new</span> Event("<span class="quote">dataFieldChanged</span>"));
             invalidateProperties();
       }
  
      <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> keyField():<span class="category2">String</span> { <span class="category1">return</span> _dataField; }
  
      <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> keyField(value:<span class="category2">String</span>):<span class="category1">void</span> {
             <span class="category1">if</span> ( _dataField == value)
                  <span class="category1">return</span>;
             dataField = value;
       }
  
      <span class="category1">private</span> <span class="category1">var</span> _candidateValue:<span class="category2">Object</span> = <span class="category1">null</span>;
      <span class="category1">private</span> <span class="category1">var</span> _valueChanged:<span class="category2">Boolean</span>  = <span class="category1">false</span>;
  
      [Bindable("<span class="quote">change</span>")]
      [Bindable("<span class="quote">valueCommit</span>")]
      [Inspectable(defaultValue="<span class="quote">0</span>", category="<span class="quote">General</span>", verbose="<span class="quote">1</span>")]
  
      <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> value(value:<span class="category2">Object</span>) : <span class="category1">void</span> {
             <span class="category1">if</span> (value == <span class="category1">this</span>.value)
                  <span class="category1">return</span>;
   
            _candidateValue = value;
            _valueChanged = <span class="category1">true</span>;
            invalidateProperties();
       }
  
      override <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> value():<span class="category2">Object</span> {
            <span class="category1">if</span> (editable)
               <span class="category1">return</span> <span class="category2">text</span>;
   
            <span class="category1">var</span> item:<span class="category2">Object</span> = selectedItem;
   
            <span class="category1">if</span> (item == <span class="category1">null</span> )
               <span class="category1">return</span> <span class="category1">null</span>;
   
            <span class="category1">return</span> dataField <span class="category1">in</span> item ? item[dataField] : <span class="category1">null</span><span class="blockcomment">/*item[labelField]*/</span>;
       }
  
      override <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> dataProvider(value:<span class="category2">Object</span>):<span class="category1">void</span> {
              <span class="category1">if</span> ( !_valueChanged ) {
                   _candidateValue = <span class="category1">this</span>.value;
                   _valueChanged = <span class="category1">true</span>;
               }
              <span class="category1">super</span>.dataProvider = value;
       }
  
      override <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> <span class="category2">data</span>(<span class="category2">data</span>:<span class="category2">Object</span>):<span class="category1">void</span> {
            <span class="category1">super</span>.<span class="category2">data</span> = <span class="category2">data</span>;
            <span class="category1">if</span> (listData is DataGridListData) {
               _candidateValue = <span class="category2">data</span>[DataGridListData(listData).dataField];
               _valueChanged = <span class="category1">true</span>;
               invalidateProperties();
             }<span class="category1">else</span> <span class="category1">if</span> (listData is ListData &amp;&amp; ListData(listData).labelField
    <span class="category1">in</span> <span class="category2">data</span>) {
               _candidateValue = <span class="category2">data</span>[ListData(listData).labelField];
               _valueChanged = <span class="category1">true</span>;
               invalidateProperties();
             }
           }
  
      override protected <span class="category1">function</span> commitProperties():<span class="category1">void</span> {
            <span class="category1">super</span>.commitProperties();
            <span class="category1">if</span> (_dataFieldChanged) {
                   <span class="category1">if</span> (!_valueChanged &amp;&amp; !editable)
                      dispatchEvent( <span class="category1">new</span> Event(Event.CHANGE) );
    
                   _dataFieldChanged = <span class="category1">false</span>;
             }
   
            <span class="category1">if</span> (_valueChanged) {
                 applyValue(_candidateValue);
                 _candidateValue = <span class="category1">null</span>;
                 _valueChanged = <span class="category1">false</span>;
             }
       }
  
      <span class="category1">public</span> <span class="category1">function</span> lookupValue(value:<span class="category2">Object</span>, lookupField:<span class="category2">String</span> = <span class="category1">null</span>):<span class="category2">Object</span> {
         <span class="category1">var</span> result:<span class="category2">Object</span> = <span class="category1">null</span>;
         <span class="category1">var</span> cursor:IViewCursor = collectionIterator;
         <span class="category1">for</span> (cursor.<span class="category2">seek</span>(CursorBookmark.FIRST);!cursor.afterLast;cursor.moveNext()) {
               <span class="category1">var</span> entry:<span class="category2">Object</span> = cursor.current;
               <span class="category1">if</span> ( value == entry[dataField] ) {
                   result = !lookupField ? entry[labelField] : entry[lookupField];
                   <span class="category1">return</span> result;
                }
          }
         <span class="category1">return</span> result;
       }
   }
}</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>The new property <code class="literal">value</code> is assigned
in the following setter function:</p>
<a name="I_programlisting3_d1e8562" id=
"I_programlisting3_d1e8562"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>[Bindable("<span class="quote">change</span>")]
   [Bindable("<span class="quote">valueCommit</span>")]
   [Inspectable(defaultValue="<span class="quote">0</span>", category="<span class="quote">General</span>", verbose="<span class="quote">1</span>")]
    <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> value(value:<span class="category2">Object</span>) : <span class="category1">void</span> {
       <span class="category1">if</span> (value == <span class="category1">this</span>.value)
           <span class="category1">return</span>;
 
       _candidateValue = value;
       _valueChanged = <span class="category1">true</span>;
       invalidateProperties();
     }</pre>
</code>

</div></div> 
<p>Notice when the function turns on the flag <code class=
"literal">_valueChanged</code>, <code class=
"literal">invalidateProperties()</code>internally schedules a call
to the method <code class="literal">commitProperties()</code> to
ensure that all changes will be applied in the required sequence.
In the example's case, the code in the <code class=
"literal">commitProperties()</code> function ensures that the value
of the <code class="literal">dataField</code> is processed before
explicit changes to the <code class="literal">value</code>
property, if any.</p>
<p><code class="literal">ComboBox</code> is an asynchronous control
that can be populated by making server-side call. There is no
guarantee that the remote data has arrived by the time when and
when you assign some data to the <code class="literal">value</code>
property. The <code class="literal">_candidateValue</code> in the
<code class="literal">value</code> setter is a temporary variable
supporting deferred assignment in the method <code class=
"literal">commitProperties()</code>.</p>
<p>The function <code class="literal">commitProperties()</code>
broadcasts the notification that the <code class=
"literal">value</code> has been changed (in case if some other
application object is bound to this value) and passes the
<code class="literal">_candidateValue</code> to the method
<code class="literal">applyValue()</code>.</p>
<a name="I_programlisting3_d1e8615" id=
"I_programlisting3_d1e8615"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>override protected <span class="category1">function</span> commitProperties():<span class="category1">void</span> {
          <span class="category1">super</span>.commitProperties();
          <span class="category1">if</span> (_dataFieldChanged) {
                 <span class="category1">if</span> (!_valueChanged &amp;&amp; !editable)
                   dispatchEvent( <span class="category1">new</span> Event(Event.CHANGE) );
  
              _dataFieldChanged = <span class="category1">false</span>;
           }
 
          <span class="category1">if</span> (_valueChanged) {
               applyValue(_candidateValue);
               _candidateValue = <span class="category1">null</span>;
               _valueChanged = <span class="category1">false</span>;
           }
     }</pre>
</code>

</div></div> 

<p>The method <code class="literal">applyValue()</code> loops
through the collection in the <code class=
"literal">dataProvider</code> using the <code class=
"literal">IViewCursor</code> iterator. When this code finds the
object in the data collection that has a property specified in the
<code class="literal">dataField</code> with the same value as the
argument of this function, it marks this row as selected.</p>
<a name="I_programlisting3_d1e8661" id=
"I_programlisting3_d1e8661"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>protected <span class="category1">function</span> applyValue(value:<span class="category2">Object</span>):<span class="category1">void</span> {
        <span class="category1">if</span> ((value != <span class="category1">null</span>) &amp;&amp; (dataProvider != <span class="category1">null</span>)) {
            <span class="category1">var</span> cursor:IViewCursor = (dataProvider as
   ICollectionView).createCursor( );
                 <span class="category1">var</span> i:uint = 0;
                  <span class="category1">for</span> (cursor.<span class="category2">seek</span>( CursorBookmark.FIRST ); !cursor.afterLast;
                                                           cursor.moveNext(), i++) {
                       <span class="category1">var</span> entry:<span class="category2">Object</span> = cursor.current;
                       <span class="category1">if</span> ( !entry ) <span class="category1">continue</span>;
                       <span class="category1">if</span> ( (dataField <span class="category1">in</span> entry &amp;&amp; value == entry[dataField])) {
                            selectedIndex = i;
                            <span class="category1">return</span>;
                        }
                   }
              }
             selectedIndex = -1;
         }</pre>
</code>

</div></div> 
<p>Tags such as</p>
<p><code class=
"literal">[Inspectable(defaultValue="0",category="General",
verbose="1")]</code></p>
<p>ensure that corresponding properties will appear in property
sheets of <code class="literal">ComboBoxBase</code> in Flex
Builder's design mode (in this case under the category <span class=
"emphasis"><em>General</em></span> with specified initial values in
<code class="literal">defaultValue</code> and <code class=
"literal">verbose</code>).</p>
<p>Metatags such as <code class=
"literal">[Bindable("dataFieldChanged")]</code> ensure that the
<code class="literal">dataFieldChange</code> event will be
dispatched (to those who care) whenever the value of the
<code class="literal">dataField</code> changes.</p>
<p>This small application <span class=
"emphasis"><em>TestComboBoxApp.mxml</em></span> demonstrates the
use of the <code class="literal">ComboBoxBase</code> component.</p>
<div class="example"><a name="using_the_comboboxbase_compo" id=
"using_the_comboboxbase_compo"></a>
<p class="title"><b>Example&nbsp;3.7.&nbsp;Using the ComboBoxBase
component</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:<span class="category2">Application</span> xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:<span class="category2">clear</span>="<span class="quote">com.farata.controls.*</span>" layout="<span class="quote">vertical</span>"&gt;
    &lt;mx:ArrayCollection id="<span class="quote">cbData</span>"&gt;
          &lt;mx:<span class="category2">Array</span>&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category1">label</span>="<span class="quote">Adobe</span>" <span class="category2">data</span>="<span class="quote">ADBE</span>" taxID="<span class="quote">1111</span>"/&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category1">label</span>="<span class="quote">Microsoft</span>" <span class="category2">data</span>="<span class="quote">MSFT</span>"  taxID="<span class="quote">2222</span>"/&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category1">label</span>="<span class="quote">Farata Systems</span>" <span class="category2">data</span>="<span class="quote">FS</span>"  taxID="<span class="quote">3333</span>"/&gt;
          &lt;/mx:<span class="category2">Array</span>&gt;
    &lt;/mx:ArrayCollection&gt;

    &lt;<span class="category2">clear</span>:ComboBoxBase  dataProvider="<span class="quote">{cbData}</span>" value="<span class="quote">FS</span>"/&gt;

    &lt;<span class="category2">clear</span>:ComboBoxBase  dataProvider="<span class="quote">{cbData}</span>" dataField="<span class="quote">taxID</span>" value="<span class="quote">3333</span>"/&gt;

&lt;/mx:<span class="category2">Application</span>&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>Both dropdowns use the same <code class=
"literal">dataProvider</code>. When you run <a href=
"#using_the_comboboxbase_compo" title=
"Example&nbsp;3.7.&nbsp;Using the ComboBoxBase component">Example&nbsp;3.7,
&ldquo;Using the ComboBoxBase component&rdquo;</a>'s application,
you'll see a window similar to <a href=
"#running_an_application_with" title=
"Figure&nbsp;3.4.&nbsp;Running an application with two ComboBoxBase components">
Figure&nbsp;3.4, &ldquo;Running an application with two
ComboBoxBase components&rdquo;</a>. window:</p>
<div class="figure"><a name="running_an_application_with" id=
"running_an_application_with"></a>
<p class="title"><b>Figure&nbsp;3.4.&nbsp;Running an application
with two ComboBoxBase components</b></p>
<div class="figure-contents">
<div class="mediaobject"><a name="I_mediaobject3_d1e8765" id=
"I_mediaobject3_d1e8765"></a><img src="http://www.insideria.com/riaimages/edwf_0304.png" alt=
"Running an application with two ComboBoxBase components" /></div>
</div>
</div>
<br class="figure-break" />
<p>The first <code class="literal">ComboBoxBase</code> shows Farata
System because of the assignment <code class=
"literal">value="FS"</code> that compares it with values in the
<code class="literal">data</code> field of the objects from
<code class="literal">cbData</code> collection.</p>
<p>The second dropdown sets <code class=
"literal">dataField="taxID"</code> that instructs the <code class=
"literal">ComboBox</code> to use the value of <code class=
"literal">taxID</code> property in the underlying data collection.
If the code will assign a new value to <code class=
"literal">taxID</code>, i.e. an external data feed, the selection
in the <code class="literal">ComboBox</code> will change
accordingly. This behavior better relates to the real-world
situations where a collection of DTO with multiple properties
arrives from the server and has to be used with one or more
<code class="literal">ComboBox</code> controls that may consider
different DTO properties as their data.</p>
</div>

<div class="titlepage">
<div>
<div>
<h2 class="title"><a name=
"resources_as_properties_of_ui_controls" id=
"resources_as_properties_of_ui_controls"></a>Resources as
Properties of UI Controls</h2>
</div>
</div>
</div>
<p>Even more flexible solution for enhancing components to better
support your enterprise framework is through the use of a
programming technique that we call <span class="emphasis"><em>data
styling</em></span> or Business Style Sheets (BSS). The basic
process is to create small files, called <span class=
"emphasis"><em>resources</em></span>, and attach them as a property
to a regular UI component as well as a <code class=
"literal">DataGrid</code> column.</p>
<p><a href="#a_checkbox_resource" title=
"Example&nbsp;3.8.&nbsp;A CheckBox resource">Example&nbsp;3.8,
&ldquo;A CheckBox resource&rdquo;</a> illustrates this <span class=
"emphasis"><em>BSS technique</em></span> and contains a small MXML
file called <span class=
"emphasis"><em>YesNoCheckBoxResource.mxml</em></span>:</p>
<div class="example"><a name="a_checkbox_resource" id=
"a_checkbox_resource"></a>
<p class="title"><b>Example&nbsp;3.8.&nbsp;A CheckBox
resource</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;fx:CheckBoxResource
    xmlns="<span class="quote">com.farata.resources</span>" xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:resources="<span class="quote">com.theriabook.resources.*</span>"
    offValue = "<span class="quote">N</span>"
    onValue = "<span class="quote">Y</span>"
    <span class="category2">textAlign</span>="<span class="quote">center</span>"
    &gt;

&lt;/fx:CheckBoxResource&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>Doesn't it look like a style to you? You can easily make it
specific to a locale too by, for example changing the on/off values
of Y/N to &#1044;./&#1053;, which mean
&#1044;&#1072;/&#1053;&#1077;&#1090; in Russian, or Si/No for
Spanish. When you think of such resources as of entities that are
separate from the application components, you begin to see the
flexibility of the technique. Isn't such functionality similar to
what CSS is about?</p>
<p>As a matter of fact, it's more sophisticated than CSS because
this resource is a mix of styles and properties, as shown in
<a href="#statecomboboxresource_with" title=
"Example&nbsp;3.9.&nbsp;StateComboBoxResource with hard-coded states">
Example&nbsp;3.9, &ldquo;StateComboBoxResource with hard-coded
states&rdquo;</a>. Called <span class=
"emphasis"><em>StateComboBoxResource.mxml</em></span>, this
resource demonstrates using properties (i.e. <code class=
"literal">dataProvider</code>) in a BSS. Such a resource can
contain a list of values such as names and abbreviations of
states:</p>
<div class="example"><a name="statecomboboxresource_with" id=
"statecomboboxresource_with"></a>
<p class="title"><b>Example&nbsp;3.9.&nbsp;StateComboBoxResource
with hard-coded states</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;fx:ComboBoxResource
    xmlns="<span class="quote">com.farata.resources</span>" xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:resources="<span class="quote">com.theriabook.resources.*</span>"
    dropdownWidth="<span class="quote">160</span>"
    <span class="category2">width</span>="<span class="quote">160</span>"
    &gt;
    &lt;fx:dataProvider&gt;
          &lt;mx:<span class="category2">Array</span>&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">AL</span>" <span class="category1">label</span>="<span class="quote">Alabama</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">AZ</span>" <span class="category1">label</span>="<span class="quote">Arizona</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">CA</span>" <span class="category1">label</span>="<span class="quote">California</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">CO</span>" <span class="category1">label</span>="<span class="quote">Colorado</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">CT</span>" <span class="category1">label</span>="<span class="quote">Connecticut</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">DE</span>" <span class="category1">label</span>="<span class="quote">Delaware</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">FL</span>" <span class="category1">label</span>="<span class="quote">Florida</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">GA</span>" <span class="category1">label</span>="<span class="quote">Georgia</span>" /&gt;
               &lt;mx:<span class="category2">Object</span> <span class="category2">data</span>="<span class="quote">WY</span>" <span class="category1">label</span>="<span class="quote">Wyoming</span>" /&gt;
          &lt;/mx:<span class="category2">Array</span>&gt;
    &lt;/fx:dataProvider&gt;
&lt;/fx:ComboBoxResource&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>Yet another example of a resource, <a href=
"#sample_departmentcomboreso" title=
"Example&nbsp;3.10.&nbsp;Sample DepartmentComboResource configured for a remote destination">
Example&nbsp;3.10, &ldquo;Sample DepartmentComboResource configured
for a remote destination&rdquo;</a> contains a reference to remote
destination for automatic retrieval of dynamic data coming from a
DBMS:</p>
<div class="example"><a name="sample_departmentcomboreso" id=
"sample_departmentcomboreso"></a>
<p class="title"><b>Example&nbsp;3.10.&nbsp;Sample
DepartmentComboResource configured for a remote destination</b></p>
<div class="example-contents">
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;fx:ComboBoxResource
    xmlns="<span class="quote">com.farata.resources</span>" xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>"
    xmlns:resources="<span class="quote">com.theriabook.resources.*</span>"
    <span class="category2">width</span>="<span class="quote">160</span>"
    dropdownWidth="<span class="quote">160</span>"
    destination="<span class="quote">Employee</span>"
    keyField="<span class="quote">DEPT_ID</span>"
    labelField="<span class="quote">DEPT_NAME</span>"
    autoFill="<span class="quote">true</span>"
    <span class="category1">method</span>="<span class="quote">getDepartments</span>"
    &gt;
&lt;/fx:ComboBoxResource&gt;</pre>
</code>

</div></div> </div>
</div>
<br class="example-break" />
<p>As a matter of fact, you can't say from this code if the data is
coming from a DBMS or from somewhere else. That data is cleanly
separated from the instances of the <code class=
"literal">ComboBox</code> objects associated with this particular
resource and can be cached either globally (if the data needs to be
retrieved once) or according to the framework caching
specifications. When developing a business framework you may allow,
for example, lookup objects to be loaded once per application or
once per view. This flexibility doesn't exist in singleton-based
architectural frameworks. Frameworks built using the resource
technique/BSS, however, do allow the flexibility to lookup
objects.</p>
<p>Based on this resource file you can only say that the data comes
back from a remote destination called <code class=
"literal">Employee</code>, which is either a name of a class or a
class factory. You can also see that the method <code class=
"literal">getDepartments()</code> will return the data containing
<code class="literal">DEPT_ID</code> and <code class=
"literal">DEPT_NAME</code> that will be used with the enhanced
<code class="literal">ComboBox</code> described earlier in this
chapter (<a href="#class_com.farata.control.co" title=
"Example&nbsp;3.6.&nbsp;Class com.farata.control.ComboBoxBase">Example&nbsp;3.6,
&ldquo;Class com.farata.control.ComboBoxBase&rdquo;</a>).</p>
<p>In addition to such resources, however, you need a mechanism of
attaching them to Flex UI components. To teach a <code class=
"literal">ComboBox</code> to work with resources, add a
<code class="literal">resource</code> property to it:</p>
<a name="I_programlisting3_d1e8893" id=
"I_programlisting3_d1e8893"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre><span class="category1">private</span> <span class="category1">var</span> _resource:<span class="category2">Object</span>;
          <span class="category1">public</span> <span class="category1">function</span> <span class="category2">get</span> resource():<span class="category2">Object</span>
          {
                <span class="category1">return</span> _resource;
           }

          <span class="category1">public</span> <span class="category1">function</span> <span class="category1">set</span> resource(value:<span class="category2">Object</span>):<span class="category1">void</span> {
                _resource = value;
                <span class="category1">var</span> objInst:*  = ResourceBase.getResourceInstance(value);
                <span class="category1">if</span>(objInst)
                      objInst.<span class="category2">apply</span>(<span class="category1">this</span>);
           }</pre>
</code>

</div></div> 
<p>The section "<a href="#the_base_class_for_resources"
title="The Base Class for Resources">the section called &ldquo;The
Base Class for Resources&rdquo;</a>" will detail the <code class=
"literal">ResourceBase</code> class. For now, concentrate on the
fact that the <code class="literal">resource</code> property
enables you to write something like this:</p>
<a name="I_programlisting3_d1e8929" id=
"I_programlisting3_d1e8929"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>&lt;fx:ComboBox resource="<span class="quote">{DepartmentComboResource}</span>"</pre>
</code>

</div></div> 
<p>Each of the enhanced UI components in your framework should
include such property. Because interfaces don't allow default
implementation of such setter and getter and because ActionScript
does not support multiple inheritance, the easiest way to include
this implementation of the <code class="literal">resource</code>
property to each control is by using the language compile-time
directive <code class="literal">#include</code>, which includes the
contents of the external file, say <span class=
"emphasis"><em>resource.as</em></span>, into the code of your
components:</p>
<a name="I_programlisting3_d1e8942" id=
"I_programlisting3_d1e8942"></a>
<div class="acode" style="overflow: auto;" ><div style="overflow-x: visible;">
<code language="perl">
<pre><span class="category1">#include</span> "<span class="quote">resource.as</span>"</pre>
</code>

</div></div>

 <div class="titlepage">
<div>
<div>
<h3 class="title"><a name="styles_vs._properties" id=
"styles_vs._properties"></a>Styles vs. Properties</h3>
</div>
</div>
</div>
<p>Before going too deep into the BSS and resources approach, you
need to understand some key differences between styles and
properties. For instance, although simple dot notation
(<code class="literal">myObject.resource=value</code>) is valid
Flex syntax for properties, it is not allowed for styles. Instead,
application programmers have to use the function <code class=
"literal">setStyle()</code>. Suffice to say the <code class=
"literal">StyleManager</code> handles styles that can be cascading,
while properties can't cascade. From the framework developer's
point of view, properties allow defining classes with getters and
setters and take advantage of inheritance. With styles, you can't
do this. On the other hand, you can't add properties (i.e. value
and destination) to styles.</p>
<p>Designers of Flex framework separated styles from properties for
easier separation of internal processes &ndash; if an application
code changes the style, Flex frameworks performs some underground
work to ensure that cascading style conventions are properly
applied; for example, global style that dictates Verdana font
family is properly <span class=
"emphasis"><em>overridden</em></span> by the style applied to a
<code class="literal">Panel</code> or its child.</p>
<p>From the designer of an enterprise framework perspective, this
means that if you create a base class for the styles, and some time
later, decide to change it, the change may affect all derived
classes. Suppose you subclassed <code class=
"literal">ComboBox</code> and defined some new styles in derived
<code class="literal">MyComboBox</code> and then later you change
the style of the <code class="literal">ComboBox</code>. For the
descendent class this means that now code changes are required to
properly (according to the changed rules) apply the overridden and
added styles.</p>
<p>All this explains, why every book and product manual keeps
warning that styles are expensive and you should limit the use of
the <code class="literal">setSyle()</code> function during the
runtime. With properties, life is a lot easier.</p>
<p>A beneficial framework would allow application programmers to
define a small named set of application-specific styles and
properties and the ability to govern the work of the UI control
with selectors.</p>
<p>To accomplish this, get into the <code class=
"literal">DataGrid</code> state of mind</p>
<p>Have you ever thought of how a <code class=
"literal">DataGridColumn</code> object sets its own width, height
and other values? The <code class="literal">DataGridColumn</code>
class is a descendent of a style selector called <code class=
"literal">CSSStyleSelector</code>, which means it can be used to
modify styles but not properties.</p>
<p><code class="literal">DataGrid</code> examines every
<code class="literal">DataGridColumn</code> and asks itself, "Do I
have the same as this column object in my cache?" If it does not,
it answers, "Nope, there's nothing I can reuse. I need to create a
new class factory to supply a new item renderer." After this is
done, the <code class="literal">DataGrid</code> code assigns the
supplied <code class="literal">DataGridColumn</code> to item
renderer as a style. (Search for <code class=
"literal">renderer.styleName=c</code> in the code of <span class=
"emphasis"><em>DataGridBase.as</em></span> to see for yourself. )
At this point, all the specified column's styles (height, width,
color, text alignment) are applied as styles to the item
renderer.</p>
<p>Treat <code class="literal">DataGridColumn</code> as a CSS style
selector that also includes a limited number of properties (i.e.
<code class="literal">itemRenderer</code>). <code class=
"literal">DataGrid</code> creates on instance of such selector
object and then re-applies it to ever cell in this column.</p>
<p>Unfortunately, designing a <code class="literal">DataGrid</code>
this way makes it next to impossible to externalize this CSS style
selector, and you can't extend the properties of the data grid
column to make them specific to the item renderer. Say, you wanted
to use a <code class="literal">CheckBox</code> with a property
<code class="literal">value</code> (on/off) as an item renderer.
Tough luck &ndash; <code class="literal">DataGridColumn</code> is
not a dynamic object and you can't just add this as a new
property.</p>
<p>Flex is an extendable framework, however, and what you
<span class="emphasis"><em>can</em></span> add is a new resource
class with behaviors more to your liking. In fact, that's exactly
what the <code class="literal">ResourceBase</code> class does, and
it's described next.</p>

<p><strong>Continue to <a href="http://www.insideria.com/2009/05/building-an-enterprise-framewo.html">Part 2</a> of this chapter.</strong></p>
]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059033</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059033" />
    <title>Comment from Benji Smith on 2009-05-07</title>
    <author>
        <name>Benji Smith</name>
        <uri>http://benjismith.net</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://benjismith.net">
        <![CDATA[<p>Oops. Your HTMLs are showing :)</p>]]>
    </content>
    <published>2009-05-07T16:10:44Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059079</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059079" />
    <title>Comment from Raven on 2009-05-07</title>
    <author>
        <name>Raven</name>
        <uri>http://www.ravenzh.cn</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.ravenzh.cn">
        <![CDATA[<p>Can not understand the lay out . Also the code editor was so terrible that we even could see HTML tags like "span". God , please save me</p>]]>
    </content>
    <published>2009-05-08T04:47:46Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059112</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059112" />
    <title>Comment from Rachelj on 2009-05-08</title>
    <author>
        <name>Rachelj</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hey guys, thanks for catching this. Obviously, the producer (me!) wasn't paying enough attention when prepping this excerpt. The extraneous tags have been removed. </p>]]>
    </content>
    <published>2009-05-08T14:07:32Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059115</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059115" />
    <title>Comment from Yakov Fain on 2009-05-08</title>
    <author>
        <name>Yakov Fain</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>There's more cleanup to be done. All &lt; and &gt; have to be replaced with  correspondingly.</p>]]>
    </content>
    <published>2009-05-08T14:36:48Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059123</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059123" />
    <title>Comment from Rachelj on 2009-05-08</title>
    <author>
        <name>Rachelj</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Sorry about that, our code formatting seems to have gotten things backward here. This is fixed now also.</p>]]>
    </content>
    <published>2009-05-08T15:50:55Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059125</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059125" />
    <title>Comment from Yakov Fain on 2009-05-08</title>
    <author>
        <name>Yakov Fain</name>
        <uri>http://yakovfain.javadevelopersjournal.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://yakovfain.javadevelopersjournal.com">
        <![CDATA[<p>Almost there :)</p>

<p>The escaped minus sign seems to be the last thing to fix (just search for the word minus).</p>]]>
    </content>
    <published>2009-05-08T15:58:07Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059176</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059176" />
    <title>Comment from yurec on 2009-05-08</title>
    <author>
        <name>yurec</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>"and you can simply set textAlign=true on DataGridColumn." seems to be "and you can simply set textAlign=center on DataGridColumn."<br />
and<br />
var val:String; val= 'Texas' ;<br />
for (var i: int = 0; i 
     if ( val == cbx_states.dataProvider[i].label) {<br />
        cbx_states.selectedIndex = i;<br />
        break;<br />
    }<br />
}<br />
=><br />
var val:String; val= 'Texas' ;<br />
for (var i: int = 0; i 
     if ( val == cbx_states.dataProvider[i][labelField]) {<br />
        cbx_states.selectedIndex = i;<br />
        break;<br />
    }<br />
}</p>]]>
    </content>
    <published>2009-05-09T04:56:58Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36026-comment:2059256</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36026" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/05/chapter-preview-building-an-en.html#comment-2059256" />
    <title>Comment from Human League on 2009-05-10</title>
    <author>
        <name>Human League</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>"We're only human,</p>

<p>Born to make mistakes....!"</p>]]>
    </content>
    <published>2009-05-10T14:52:33Z</published>
  </entry>

</feed
