<?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; resultFormat</title>
	<atom:link href="http://blog.flexexamples.com/tag/resultformat/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>Passing parameters to an HTTPService</title>
		<link>http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/</link>
		<comments>http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 06:21:37 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[StringValidator]]></category>
		<category><![CDATA[ValidationResultEvent]]></category>
		<category><![CDATA[resultFormat]]></category>
		<category><![CDATA[send()]]></category>
		<category><![CDATA[validate()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/</guid>
		<description><![CDATA[<p>The followig example shows how you can pass parameters to an HTTPService by passing an Object in the HTTPService&#8217;s send() method. The remote ColdFusion script is a simple &#8220;hello world&#8221; type script which accepts a single parameter, &#8220;name&#8221;, and returns a single parameter, &#8220;welcomeMessage&#8221;.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_send_test/main.mxml">View MXML</a></p> &#60;?xml [...]]]></description>
			<content:encoded><![CDATA[<p>The followig example shows how you can pass parameters to an HTTPService by passing an Object in the HTTPService&#8217;s <code>send()</code> method. The remote ColdFusion script is a simple &#8220;hello world&#8221; type script which accepts a single parameter, &#8220;name&#8221;, and returns a single parameter, &#8220;welcomeMessage&#8221;.</p>
<p>Full code after the jump.</p>
<p><span id="more-257"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_send_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;
            import mx.events.ValidationResultEvent;
            import mx.utils.StringUtil;

            private function submit_click(evt:MouseEvent):void {
                var result:ValidationResultEvent = stringValidator.validate();
                var params:Object = {};

                lbl.text = "";

                switch (result.type) {
                    case ValidationResultEvent.INVALID:
                        Alert.show(result.message, result.type);
                        break;
                    case ValidationResultEvent.VALID:
                        params["name"] = StringUtil.trim(firstName.text);
                        httpServ.send(params);
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:StringValidator id="stringValidator"
            source="{firstName}"
            property="text"
            minLength="2"
            maxLength="{firstName.maxChars}" /&gt;

    &lt;mx:HTTPService id="httpServ"&gt;
        &lt;mx:resultFormat&gt;flashvars&lt;/mx:resultFormat&gt;
        &lt;mx:url&gt;http://www.flash-mx.com/mm/greeting.cfm&lt;/mx:url&gt;
        &lt;mx:result&gt;lbl.text = httpServ.lastResult.welcomeMessage;&lt;/mx:result&gt;
        &lt;mx:fault&gt;Alert.show(event.toString(), event.type);&lt;/mx:fault&gt;
    &lt;/mx:HTTPService&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Form&gt;
            &lt;mx:FormItem label="Name:" required="true"
                    direction="horizontal"&gt;
                &lt;mx:TextInput id="firstName"
                    maxChars="20" /&gt;
                &lt;mx:Button label="Submit"
                        click="submit_click(event);" /&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Label id="lbl" fontSize="32" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_send_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/HTTPService_send_test/bin/main.html" width="100%" height="200"></iframe></p>
<p class="new">By popular request, here is the ColdFusion source code as well.</p>
<p class="download">http://www.flash-mx.com/mm/greeting.cfm</p>
<pre class="code">
&lt;cfsilent&gt;
&lt;cfsetting enablecfoutputonly=&quot;Yes&quot;&gt;
&lt;cfif IsDefined(&quot;URL.name&quot;)&gt;&lt;cfset Form.Name = URL.name /&gt;&lt;/cfif&gt;
&lt;cfif NOT IsDefined(&quot;Form.name&quot;) OR Len(Trim(Form.Name)) EQ 0&gt;
    &lt;cfset Form.Name = &quot;[Mysterious Stranger]&quot; /&gt;
&lt;/cfif&gt;
&lt;/cfsilent&gt;&lt;cfcontent reset=&quot;true&quot; /&gt;&lt;cfoutput&gt;welcomeMessage=#UrlEncodedFormat(&quot;Welcome, &quot;&#038;Form.name)#&lt;/cfoutput&gt;
&lt;cfsetting enablecfoutputonly=&quot;No&quot;&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Passing parameters to an HTTPService on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/10/29/passing-parameters-to-an-httpservice/',contentID: 'post-257',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'resultFormat,send(),validate()',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/10/29/passing-parameters-to-an-httpservice/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Converting XML to objects using the Flex HTTPService MXML tag</title>
		<link>http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/</link>
		<comments>http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 02:53:21 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[HTTPService]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[resultFormat]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/</guid>
		<description><![CDATA[<p>The following example shows how you can convert an XML file loaded at run-time using the HTTPService tag, into an ActionScript Object by simply setting the resultFormat property to &#8220;object&#8221;.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_resultFormat_test/main.mxml">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="serv.send();"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can convert an XML file loaded at run-time using the HTTPService tag, into an ActionScript Object by simply setting the <code>resultFormat</code> property to &#8220;object&#8221;.</p>
<p>Full code after the jump.</p>
<p><span id="more-193"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_resultFormat_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="serv.send();"&gt;

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

            private function serv_result(evt:ResultEvent):void {
                var resultObj:Object = evt.result;
                /* Assign the values... */
                nameText.text = resultObj.album.name;
                img0Text.text = resultObj.album.images.image[0];
                img1Text.text = resultObj.album.images.image[1];
                img2Text.text = resultObj.album.images.image[2];
            }

            private function serv_fault(evt:FaultEvent):void {
                /* Show the error label. */
                error.text += evt.fault.faultString;
                error.visible = true;
                /* Hide the form. */
                form.visible = false;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:String id="XML_URL"&gt;album.xml&lt;/mx:String&gt;

    &lt;mx:HTTPService id="serv"
            url="{XML_URL}"
            resultFormat="object"
            result="serv_result(event);"
            fault="serv_fault(event);" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="{XML_URL}" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Label id="error"
            color="red"
            fontSize="36"
            fontWeight="bold"
            visible="false"
            includeInLayout="{error.visible}"/&gt;

    &lt;mx:Form id="form"
            includeInLayout="{form.visible}"&gt;
        &lt;mx:FormItem label="resultObj.album.name:"&gt;
            &lt;mx:Label id="nameText" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[0]:"&gt;
            &lt;mx:Label id="img0Text" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[1]:"&gt;
            &lt;mx:Label id="img1Text" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="resultObj.album.images.image[2]:"&gt;
            &lt;mx:Label id="img2Text" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_resultFormat_test/bin/album.xml">View album.xml</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;album&gt;
    &lt;name&gt;One&lt;/name&gt;
    &lt;images&gt;
        &lt;image&gt;image1.jpg&lt;/image&gt;
        &lt;image&gt;image2.jpg&lt;/image&gt;
        &lt;image&gt;image3.jpg&lt;/image&gt;
    &lt;/images&gt;
&lt;/album&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/HTTPService_resultFormat_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/HTTPService_resultFormat_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Converting XML to objects using the Flex HTTPService MXML tag on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/',contentID: 'post-193',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/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<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>

