<?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; name/value pairs</title>
	<atom:link href="http://blog.flexexamples.com/tag/namevalue-pairs/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 files using the URLLoader and URLVariables classes</title>
		<link>http://blog.flexexamples.com/2007/07/28/loading-files-using-the-urlloader-and-urlvariables-classes/</link>
		<comments>http://blog.flexexamples.com/2007/07/28/loading-files-using-the-urlloader-and-urlvariables-classes/#comments</comments>
		<pubDate>Sat, 28 Jul 2007 19:38:32 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[URLLoader]]></category>
		<category><![CDATA[URLRequest]]></category>
		<category><![CDATA[URLVariables]]></category>
		<category><![CDATA[name/value pairs]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/28/loading-files-using-the-urlloader-and-urlvariables-classes/</guid>
		<description><![CDATA[<p>Not sure if this is helpful to anybody, but thought I&#8217;d throw it out there. The following basic example loads some random variables from an external text file and displays the events which were dispatched in a DataGrid control, as well as the loaded name/value pairs.</p> <p>Full code after the jump.</p> <p></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure if this is helpful to anybody, but thought I&#8217;d throw it out there. The following basic example loads some random variables from an external text file and displays the events which were dispatched in a DataGrid control, as well as the loaded name/value pairs.</p>
<p>Full code after the jump.</p>
<p><span id="more-36"></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="init()"&gt;

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

            [Bindable]
            private var VARIABLES_URL:String = "params.txt";

            [Bindable]
            private var arrColl:ArrayCollection;

            [Bindable]
            private var paramColl:ArrayCollection;

            private var urlReq:URLRequest;
            private var urlLdr:URLLoader;

            private function init():void {
                /* Initialize the two ArrayCollections objects with empty arrays. */
                arrColl = new ArrayCollection();
                paramColl = new ArrayCollection();

                /* Initialize the URLRequest object with the URL to the file of name/value pairs. */
                urlReq = new URLRequest(VARIABLES_URL);

                /* Initialize the URLLoader object, assign the various event listeners, and load the specified URLRequest object. */
                urlLdr = new URLLoader();
                urlLdr.addEventListener(Event.COMPLETE, doEvent);
                urlLdr.addEventListener(Event.OPEN, doEvent);
                urlLdr.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);
                urlLdr.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
                urlLdr.addEventListener(ProgressEvent.PROGRESS, doEvent);
                urlLdr.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
                urlLdr.load(urlReq);
            }

            private function doEvent(evt:Event):void {
                arrColl.addItem({type:evt.type, idx:arrColl.length+1, eventString:evt.toString()});

                switch (evt.type) {
                    case Event.COMPLETE:
                        /* If the load was successful, create a URLVariables object from the URLLoader.data property and populate the paramColl ArrayCollection object. */
                        var ldr:URLLoader = evt.currentTarget as URLLoader;
                        var vars:URLVariables = new URLVariables(ldr.data);
                        var key:String;

                        for (key in vars) {
                            paramColl.addItem({key:key, value:vars[key]});
                        }

                        params.visible = true;
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:VBox&gt;
        &lt;mx:Label text="Events:" /&gt;
        &lt;mx:DataGrid id="events" dataProvider="{arrColl}" rowCount="5"&gt;
            &lt;mx:columns&gt;
                &lt;mx:DataGridColumn dataField="idx" headerText="#" width="20" /&gt;
                &lt;mx:DataGridColumn dataField="type" headerText="Type" showDataTips="true" dataTipField="eventString" /&gt;
            &lt;/mx:columns&gt;
        &lt;/mx:DataGrid&gt;
    &lt;/mx:VBox&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>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Loading files using the URLLoader and URLVariables classes on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/28/loading-files-using-the-urlloader-and-urlvariables-classes/',contentID: 'post-36',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'name/value pairs',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-files-using-the-urlloader-and-urlvariables-classes/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

