<?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; IViewCursor</title>
	<atom:link href="http://blog.flexexamples.com/category/iviewcursor/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>Creating a view cursor on an ArrayCollection in Flex</title>
		<link>http://blog.flexexamples.com/2008/04/15/creating-a-view-cursor-on-an-arraycollection-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/04/15/creating-a-view-cursor-on-an-arraycollection-in-flex/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 02:32:32 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ArrayCollection]]></category>
		<category><![CDATA[IViewCursor]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[createCursor]]></category>
		<category><![CDATA[current]]></category>
		<category><![CDATA[findAny()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/15/creating-a-view-cursor-on-an-arraycollection-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can create a view cursor to find a specific item within an ArrayCollection.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/IViewCursor_findAny_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/15/creating-a-view-cursor-on-an-arraycollection-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();"&#62; &#60;mx:Array id="arr"&#62; &#60;mx:String&#62;One&#60;/mx:String&#62; &#60;mx:String&#62;Two&#60;/mx:String&#62; &#60;mx:String&#62;Three&#60;/mx:String&#62; &#60;mx:String&#62;Four&#60;/mx:String&#62; &#60;mx:String&#62;Five&#60;/mx:String&#62; &#60;/mx:Array&#62; &#60;mx:ArrayCollection id="arrColl" source="{arr}" /&#62; &#60;mx:Script&#62; &#60;![CDATA[ [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can create a view cursor to find a specific item within an ArrayCollection.</p>
<p>Full code after the jump.</p>
<p><span id="more-594"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/IViewCursor_findAny_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/15/creating-a-view-cursor-on-an-arraycollection-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Array id="arr"&gt;
        &lt;mx:String&gt;One&lt;/mx:String&gt;
        &lt;mx:String&gt;Two&lt;/mx:String&gt;
        &lt;mx:String&gt;Three&lt;/mx:String&gt;
        &lt;mx:String&gt;Four&lt;/mx:String&gt;
        &lt;mx:String&gt;Five&lt;/mx:String&gt;
    &lt;/mx:Array&gt;

    &lt;mx:ArrayCollection id="arrColl" source="{arr}" /&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.collections.IViewCursor;
            import mx.collections.Sort;
            import mx.collections.SortField;

            [Embed("assets/accept.png")]
            public var acceptIcon:Class;

            [Embed("assets/exclamation.png")]
            public var exclamationIcon:Class;

            private var cursor:IViewCursor;

            private function init():void {
                var sortField:SortField = new SortField(null, true);
                var sort:Sort = new Sort();
                sort.fields = [sortField];

                arrColl.sort = sort;
                arrColl.refresh();

                cursor = arrColl.createCursor();
            }

            private function button_click(evt:MouseEvent):void {
                var found:Boolean = cursor.findAny(textInput.text);
                if (found) {
                    img.source = acceptIcon;
                    list.selectedItem = cursor.current;
                } else {
                    img.source = exclamationIcon;
                    list.selectedItem = null;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Canvas&gt;
            &lt;mx:TextInput id="textInput" /&gt;
            &lt;mx:Image id="img" right="3" verticalCenter="0" /&gt;
        &lt;/mx:Canvas&gt;
        &lt;mx:Button id="button"
                label="Find"
                click="button_click(event);" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:List id="list"
            dataProvider="{arrColl}"
            width="100"
            rowCount="{arrColl.length}" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/IViewCursor_findAny_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/IViewCursor_findAny_test/bin/main.html" width="100%" height="200"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a view cursor on an ArrayCollection in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/15/creating-a-view-cursor-on-an-arraycollection-in-flex/',contentID: 'post-594',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'createCursor,current,findAny()',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/15/creating-a-view-cursor-on-an-arraycollection-in-flex/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

