<?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>Flex Examples &#187; ResultEvent</title>
	<atom:link href="http://blog.flexexamples.com/category/resultevent/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Loading name/value pairs using the mx:HTTPService tag</title>
		<link>http://blog.flexexamples.com/2007/07/28/loading-namevalue-pairs-using-the-mxhttpservice-tag/</link>
		<comments>http://blog.flexexamples.com/2007/07/28/loading-namevalue-pairs-using-the-mxhttpservice-tag/#comments</comments>
		<pubDate>Sun, 29 Jul 2007 03:31:51 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[ResultEvent]]></category>
		<category><![CDATA[resultFormat]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/28/loading-namevalue-pairs-using-the-mxhttpservice-tag/</guid>
		<description><![CDATA[<p>Semi-related to my previous post, I was playing around and figured out a way (probably not the best method) for loading a page of remote name/value pairs and putting them in a DataGrid using the HTTPService tag.</p> <p>Full code after the jump</p> <p> </p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" verticalAlign="middle" backgroundColor="white" creationComplete="httpParams.send()"&#62; &#60;mx:HTTPService resultFormat="flashvars" url="{VARIABLES_URL}" [...]]]></description>
			<content:encoded><![CDATA[<p>Semi-related to my previous post, I was playing around and figured out a way (probably not the best method) for loading a page of remote name/value pairs and putting them in a DataGrid using the HTTPService tag.</p>
<p>Full code after the jump</p>
<p><span id="more-37"></span> </p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" verticalAlign="middle" backgroundColor="white" creationComplete="httpParams.send()"&gt;

    &lt;mx:HTTPService resultFormat="flashvars" url="{VARIABLES_URL}" id="httpParams" result="onResult(event)" /&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;

            [Bindable]
            private var VARIABLES_URL:String = "http://www.flash-mx.com/mm/params.txt";

            [Bindable]
            private var paramColl:ArrayCollection = new ArrayCollection();

            private function onResult(evt:ResultEvent):void {
                var vars:Object = evt.result;
                var key:String;

                for (key in vars) {
                    paramColl.addItem({key:key, value:vars[key]});
                }
                params.visible = true;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:VBox&gt;
        &lt;mx:Label text="Parameters:" /&gt;
        &lt;mx:DataGrid id="params" dataProvider="{paramColl}" rowCount="5" visible="false"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="key" headerText="Key" /&gt;
                &lt;mx:DataGridColumn dataField="value" headerText="Value" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;</pre>
<p>Again, I&#8217;m sure there is a nicer way of handling the ResultEvent and converting to a data provider, so you may want to play around with it a bit.</p>
<p>Of course, if you know the names of the parameters in the file that you&#8217;re loading, you could also just do something like this:</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="httpService.send()"&gt;

    &lt;mx:HTTPService id="httpService" resultFormat="flashvars" url="params.txt" /&gt;

    &lt;mx:VBox&gt;
        &lt;mx:Label text="name: {httpService.lastResult.name}" /&gt;
        &lt;mx:Label text="product: {httpService.lastResult.product}" /&gt;
        &lt;mx:Label text="powermove: {httpService.lastResult.powermove}" /&gt;
        &lt;mx:Label text="skill: {httpService.lastResult.skill}" /&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;</pre>
<p class="important">Oh, and remember, since the params.txt file is being loaded at run-time and embedded during compile-time, the params.txt file needs to be relative to the SWF file and not the MXML file.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Loading name/value pairs using the mx:HTTPService tag on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/28/loading-namevalue-pairs-using-the-mxhttpservice-tag/',contentID: 'post-37',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'resultFormat',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/28/loading-namevalue-pairs-using-the-mxhttpservice-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

