<?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; forEach()</title>
	<atom:link href="http://blog.flexexamples.com/tag/foreach/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>Looping over each item in an Array in ActionScript 3.0</title>
		<link>http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/</link>
		<comments>http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 06:52:08 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[forEach()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/</guid>
		<description><![CDATA[<p>The following example shows how you can loop over an Array object and modify items using the Array class&#8217;s forEach() method.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Array_forEach_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" initialize="init();"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import mx.utils.ObjectUtil; private function init():void { beforeTextArea.text = ObjectUtil.toString(dp); dp.forEach(forEach_test); [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can loop over an Array object and modify items using the Array class&#8217;s <code>forEach()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-603"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Array_forEach_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.ObjectUtil;

            private function init():void {
                beforeTextArea.text = ObjectUtil.toString(dp);
                dp.forEach(forEach_test);
                dataGrid.dataProvider = dp;
                afterTextArea.text = ObjectUtil.toString(dp);
            }

            private function forEach_test(element:*, index:int, arr:Array):void {
                element.lbl = element.name + " (" + element.abbr + ")";
                element.idx = index;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Array id="dp"&gt;
        &lt;mx:Object name="Baltimore Orioles" abbr="BAL" /&gt;
        &lt;mx:Object name="Boston Red Sox" abbr="BOS" /&gt;
        &lt;mx:Object name="Chicago White Sox" abbr="CWS" /&gt;
        &lt;mx:Object name="Cleveland Indians" abbr="CLE" /&gt;
        &lt;mx:Object name="Detroit Tigers" abbr="DET" /&gt;
        &lt;mx:Object name="Kansas City Royals" abbr="KC" /&gt;
        &lt;mx:Object name="Los Angeles Angels of Anaheim" abbr="LAA" /&gt;
        &lt;mx:Object name="Minnesota Twins" abbr="MIN" /&gt;
        &lt;mx:Object name="New York Yankees" abbr="NYY" /&gt;
        &lt;mx:Object name="Oakland Athletics" abbr="OAK" /&gt;
        &lt;mx:Object name="Seattle Mariners" abbr="SEA" /&gt;
        &lt;mx:Object name="Tampa Bay Devil Rays" abbr="TB" /&gt;
        &lt;mx:Object name="Texas Rangers" abbr="TEX" /&gt;
        &lt;mx:Object name="Toronto Blue Jays" abbr="TOR" /&gt;
    &lt;/mx:Array&gt;

    &lt;mx:DataGrid id="dataGrid"
            verticalScrollPolicy="on"
            width="100%"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="name" /&gt;
            &lt;mx:DataGridColumn dataField="abbr" width="80" /&gt;
            &lt;mx:DataGridColumn dataField="lbl" /&gt;
            &lt;mx:DataGridColumn dataField="idx" width="40" textAlign="right" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

    &lt;mx:Form width="100%" height="100%"&gt;
        &lt;mx:FormItem label="Before:" width="100%" height="50%"&gt;
            &lt;mx:TextArea id="beforeTextArea"
                    editable="false"
                    wordWrap="false"
                    width="100%"
                    height="100%" /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem label="After:" width="100%" height="50%"&gt;
            &lt;mx:TextArea id="afterTextArea"
                    editable="false"
                    wordWrap="false"
                    width="100%"
                    height="100%" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Array_forEach_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/Array_forEach_test/bin/main.html" width="100%" height="450"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Looping over each item in an Array in ActionScript 3.0 on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/',contentID: 'post-603',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'forEach()',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/2008/04/21/looping-over-each-item-in-an-array-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

