<?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>Eric Fickes &#187; ArrayUtil</title>
	<atom:link href="http://ericfickes.com/tag/arrayutil/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericfickes.com</link>
	<description>Design minded Internet Programmer</description>
	<lastBuildDate>Fri, 28 Oct 2011 04:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using an AS3 object or class as a DataProvider</title>
		<link>http://ericfickes.com/2010/02/using-an-as3-object-or-class-as-a-dataprovider/</link>
		<comments>http://ericfickes.com/2010/02/using-an-as3-object-or-class-as-a-dataprovider/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 22:25:12 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[adobe]]></category>
		<category><![CDATA[flash platform]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[ArrayUtil]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[dataProvider]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[ObjectUtil]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1120</guid>
		<description><![CDATA[I have a need to use custom class objects as a DataGrid dataprovider.  After wrestling with flash.utils.describeClass() I gave up and found two other methods for binding my custom objects to a DataGrid. First here is a look at the &#8230; <a href="http://ericfickes.com/2010/02/using-an-as3-object-or-class-as-a-dataprovider/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have a need to use custom class objects as a DataGrid dataprovider.  After wrestling with flash.utils.describeClass() I gave up and found two other methods for binding my custom objects to a DataGrid.</p>
<p style="text-align: center;">First here is a look at the <a title="Get the MXML source for this Object as DataGrid.dataProvider sample" href="http://ericfickes.posterous.com/two-methods-for-binding-an-as3-object-to-a-da" target="_blank">sample MXML app I put together</a>.</p>
<div id="attachment_1126" class="wp-caption aligncenter" style="width: 424px"><a href="http://ericfickes.com/wp-content/uploads/2010/02/object-databound-datagrids.png" rel="lightbox[1120]"><img class="size-full wp-image-1126" title="Using custom object as a DataGrid.dataProvider in Flex 3" src="http://ericfickes.com/wp-content/uploads/2010/02/object-databound-datagrids.png" alt="Using custom object as a DataGrid.dataProvider in Flex 3" width="414" height="277" /></a><p class="wp-caption-text">Same object bound two different ways</p></div>
<p style="text-align: center;"><a title="Run this sweet sweet Flex RIA in your own browser" href="http://ericfickes.com/code/flex/reflection/objectAsDataprovider.html" target="_blank">Click here to run this demo in a new window</a>.</p>
<p>In the first grid the DataGrid gets a column per object property.</p>
<pre class="brush: as3; title: ; notranslate">
var dp_horizontal:Array = ArrayUtil.toArray( myCustomObj );
grid_1.dataProvider = dp_horizontal.valueOf();
</pre>
<p>In the second grid, I run my custom object through a helper function to create an ArrayCollection containing NAME, VALUE pairs for each object property.</p>
<pre class="brush: as3; title: ; notranslate">
/**
 * Convert a class object into an ArrayCollection to be used
 * as a DataProvider
 */
private function objectToDataProvider( obj:Object ):ArrayCollection
{
	// our DataProvider
	var dp:ArrayCollection = new ArrayCollection();
	// get object class info
	var info:Object = mx.utils.ObjectUtil.getClassInfo( obj );
	// split the class property list into Array
	var propsA:Array = String( info.properties ).split(',');
	// loop over class properties grabbing value and filling up dp
	for( var xx:int = 0; xx &lt;= propsA.length-1; xx++)
	{
		dp.addItem( { name : propsA[ xx ], value : obj[ propsA[ xx ] ] } );
	}

	return dp;
}
</pre>
<p>I&#8217;m currently using this helper function to bind the result of WebORB.NET data calls to a DataGrid for testing.  This code could really be used by any type of object though.</p>
<p>Hope this helps somebody else.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/02/using-an-as3-object-or-class-as-a-dataprovider/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

