<?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>Stephen Gray&#039;s dev blog &#187; flex</title>
	<atom:link href="http://blog.s-gray.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.s-gray.com</link>
	<description>e-commerce and integrations</description>
	<lastBuildDate>Sun, 17 Jan 2010 09:32:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex save changes from an AdvancedDataGrid using itemEditEnd</title>
		<link>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/</link>
		<comments>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 10:38:22 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[advanceddatagrid]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[itemEditEnd]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=96</guid>
		<description><![CDATA[Quick tutorial on how to retrieve the value of an edited cell from an AdvancedDataGrid.]]></description>
			<content:encoded><![CDATA[<p>I just remembered that I had trouble finding out what I could access with this event handler function. Sure it was easy to find out when the event is dispatched, but how can I access the new field value edited by the user? How do I access the previous value?</p>
<p>So this is just a simple example showing you that. This also applies to the normal DataGrid and standard list controls.</p>
<p>The itemEditEnd event is dispatched (it&#8217;s in the name) when a user finishes editing a cell so this is pretty much the best time to save the user&#8217;s changes to that field/row.</p>
<p>Here&#8217;s our function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p96code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p961"><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
</pre></td><td class="code" id="p96code1"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> saveChange<span style="color: #66cc66;">&#40;</span>event:AdvancedDataGridEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/**
     * use event.dataField to get the edited field name
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> field:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">dataField</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * i'm using the following line to get the 'id' of the row being edited
     * because i passed an 'id' field through from my dataProvider.
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> selectedID:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">selectedItem</span>.<span style="color: #006600;">id</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * use the itemEditorInstance to get the newly edited value but retrieve
     * the previous value from the existing grid data. i'm using the default
     * textinput itemRenderer so I can retrieve the new value using the 
     * itemEditInstance's 'text' property.
     */</span>
    <span style="color: #000000; font-weight: bold;">var</span> newValue:<span style="color: #0066CC;">String</span> = event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">itemEditorInstance</span>.<span style="color: #0066CC;">text</span>;
    <span style="color: #000000; font-weight: bold;">var</span> prevValue:<span style="color: #0066CC;">String</span> = ProductPersonalisationList.<span style="color: #006600;">selectedItem</span><span style="color: #66cc66;">&#91;</span>event.<span style="color: #006600;">dataField</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">// run a http service call or something to save the change or validate the data</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/09/15/flex-save-changes-from-an-advanceddatagrid-using-itemeditend/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex getting selected RadioButton value</title>
		<link>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/</link>
		<comments>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 11:21:33 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[radio button]]></category>
		<category><![CDATA[radio button group]]></category>
		<category><![CDATA[selectedValue]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=65</guid>
		<description><![CDATA[This is a pretty simple one but there are surprisingly few tutorials showing the user simply how to get a selected RadioButtonGroup&#8217;s value.
There are quite a number of tutorials covering change event triggers for RadioButton controls but this is slightly different.
Say you have a form and you want to process the RadioButton value after submitting [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty simple one but there are surprisingly few tutorials showing the user simply how to get a selected RadioButtonGroup&#8217;s value.</p>
<p>There are quite a number of tutorials covering change event triggers for RadioButton controls but this is slightly different.</p>
<p>Say you have a form and you want to process the RadioButton value after submitting the form instead of when the value of it changes.</p>
<p>To do this you actually have to create a RadioButtonGroup MXML tag for the radio buttons and select the value using the &#8217;selectedValue&#8217; property of that RadioButtonGroup:</p>
<p><code>&lt;mx:RadioButtonGroup id="myRadioButtonGroup" enabled="true" /&gt;</code><br />
<code>&lt;mx:RadioButton label="I like RadioButtons" groupName="{myRadioButtonGroup}" left="505" top="64" selected="true" value="true"/&gt;</code><br />
<code>&lt;mx:RadioButton label="I don't like RadioButtons" groupName="{myRadioButtonGroup}" left="348" top="62" value="false"/&gt;</code></p>
<p>Notice the {} around the groupName attributes of the RadioButton controls. You can then do this to select the value:</p>
<p><code>Alert.show(myRadioButtonGroup.selectedValue.toString());</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/11/flex-getting-selected-radiobutton-value/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Flex Processing XML response from HTTPService</title>
		<link>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/</link>
		<comments>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 10:20:34 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[e4x]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[httpservice]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=17</guid>
		<description><![CDATA[There are a number of tutorials on doing this around the web but I thought I&#8217;d write my own tailored tutorial on this topic.
I&#8217;m going to cover two scenarios;
Assigning XML results as a dataProvider:
This is by far the simplest of the two:
// The initialisation function
protected function init():void
{
&#160;&#160;&#160;&#160;var serviceObj:HTTPService = new HTTPService();
&#160;&#160;&#160;&#160;serviceObj.resultFormat = 'e4x';
&#160;&#160;&#160;&#160;serviceObj.method = 'GET';
&#160;&#160;&#160;&#160;serviceObj.useProxy [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of tutorials on doing this around the web but I thought I&#8217;d write my own tailored tutorial on this topic.</p>
<p>I&#8217;m going to cover two scenarios;</p>
<p><strong>Assigning XML results as a dataProvider:</strong></p>
<p>This is by far the simplest of the two:</p>
<p><code>// The initialisation function</code><br />
<code>protected function init():void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var serviceObj:HTTPService = new HTTPService();</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.resultFormat = 'e4x';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.method = 'GET';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.useProxy = false;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.addEventListener(ResultEvent.RESULT, processResult);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.url = 'myScriptURL.php';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;serviceObj.send();</code><br />
<code>}</code></p>
<p><code>// The result processing function</code><br />
<code>protected function processResult(response:ResultEvent):void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// make sure the response is cast as the correct data type<br />
</code><code>&nbsp;&nbsp;&nbsp;&nbsp;var XMLResults:XML = response.result as XML;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;MyDataGrid.dataProvider = XMLResults.user;</code><br />
<code>}</code></p>
<p><code>// Sample XML sent from the server</code><br />
<code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;</code><br />
<code>&lt;users&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;user&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id&gt;1&lt;/id&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;username&gt;stephen&lt;/username&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;email&gt;stephen@example.com&lt;/email&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/user&gt;</code><br />
<code>&lt;/users&gt;</code></p>
<p>You&#8217;ll notice I&#8217;ve set the resultFormat attribute of the HTTPService object to be &#8216;e4x&#8217;. In my experience I&#8217;ve found e4x more useful to work with XML in Flex. e4x stands for ECMAScript for XML and <a href="http://en.wikipedia.org/wiki/E4X" target="_blank">you can find out more about it here</a>. e4x allows you to use XML as a primitive data type in your actionscript. I.E. you can do:</p>
<p><code>var myXML:XML = &lt;root&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;myNode&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;myChildNode /&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/myNode&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/root&gt;;</code></p>
<p>When using e4x as the result format, you don&#8217;t have to reference the root node when processing the XML, which is why I use the line</p>
<p><code>MyDataGrid.dataProvider = XMLResults.user;</code></p>
<p>instead of</p>
<p><code>MyDataGrid.dataProvider = XMLResults.users.user;</code></p>
<p><strong>Creating a new XML dataProvider from an existing RPC result</strong></p>
<p>This method is slightly more complicated but isn&#8217;t really needed as much. There&#8217;s really only a few situations that this would come in handy but I&#8217;ve had to use it on a recent project so I thought I may aswell post it.</p>
<p>Say you are making a call to a preexisting web service which is out of your control. In my situation, the web service WAS in my control, but it was already being used for other means so changing the output now wasn&#8217;t really an option. I wanted to process the XML, perform some logic on it and then add a new variable or two into the XML before assigning it to my DataGrid control.</p>
<p>The method I used in the end is quite simple and quick to do. You basically create a new empty XML document, loop through the results of the web service call, perform your logic and rebuild the new values into the new XML document. You then assign it to your control:</p>
<p><code>protected function processResult(response:ResultEvent):void</code><br />
<code>{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// make sure the response is cast as the correct data type</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var XMLResults:XML = response.result as XML;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// create the new XML document</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;var newXML:XML = new XML('&lt;users&gt;&lt;/users&gt;');</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;// loop through previous results</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;for (var i:String in XMLResults.users)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// userXML is going to be our new user XML record</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var userXML:XML = new XML();</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// status is the new variable I want to add to the dataProvider</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var status:String;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// perform some logic on the previous results</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (XMLResults.users.activated[i] == 1)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = 'Active';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = 'Inactive';</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// build the new XML record for this user</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// we can use {XMLResults.user.field[i]} to keep any previous elements in tact that we want to keep</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// use the {} parenthesis to put actionscript variables into the XML datatype</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userXML = </code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;user&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{XMLResults.user.username[i]}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{XMLResults.user.email[i]}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;status&gt;{status}&lt;/status&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/user&gt;;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// add the new user record to the XML document</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newXML = newXML.appendChild(userXML);</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;}</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;MyDataGrid.dataProvider = newXML;</code><br />
<code>}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/08/08/flex-processing-xml-response-from-httpservice/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

