<?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; callLater()</title>
	<atom:link href="http://blog.flexexamples.com/tag/calllater/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>Auto-scrolling a TextArea control in Flex</title>
		<link>http://blog.flexexamples.com/2008/11/27/auto-scrolling-a-textarea-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/11/27/auto-scrolling-a-textarea-control-in-flex/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 22:26:54 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[TextArea]]></category>
		<category><![CDATA[callLater()]]></category>
		<category><![CDATA[maxVerticalScrollPosition]]></category>
		<category><![CDATA[validateNow()]]></category>
		<category><![CDATA[verticalScrollPosition]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/11/27/auto-scrolling-a-textarea-control-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can auto-scroll a Flex TextArea control when new content is added by setting the verticalScrollPosition property to the value of the maxVerticalScrollPosition property.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_maxVerticalScrollPosition_text/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/11/27/auto-scrolling-a-textarea-control-in-flex/ --&#62; &#60;mx:Application name="TextArea_maxVerticalScrollPosition_text" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();"&#62; &#60;mx:Script&#62; &#60;![CDATA[ private [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can auto-scroll a Flex TextArea control when new content is added by setting the <code>verticalScrollPosition</code> property to the value of the <code>maxVerticalScrollPosition</code> property.</p>
<p>Full code after the jump.</p>
<p><span id="more-879"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_maxVerticalScrollPosition_text/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/11/27/auto-scrolling-a-textarea-control-in-flex/ --&gt;
&lt;mx:Application name="TextArea_maxVerticalScrollPosition_text"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private var timer:Timer;

            private function init():void {
                timer = new Timer(500);
                timer.addEventListener(TimerEvent.TIMER, onTimer);
                timer.start();
            }

            private function onTimer(evt:TimerEvent):void {
                var now:String = new Date().toTimeString();
                var str:String = "[" + timer.currentCount + "] " + now;
                textArea.text += str + "\\n";
                textArea.validateNow();
                textArea.verticalScrollPosition = textArea.maxVerticalScrollPosition;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:TextArea id="textArea"
            width="200"
            height="160" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_maxVerticalScrollPosition_text/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/TextArea_maxVerticalScrollPosition_text/bin/main.html" width="100%" height="220"></iframe></p>
<p>Or, instead of calling the <code>validateNow()</code> method before using the <code>verticalScrollPosition</code> and <code>maxVerticalScrollPosition</code> properties, you could use the <code>callLater()</code> method to handle the scrolling, as seen in the following example:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/TextArea_maxVerticalScrollPosition_text/bin/srcview/source/main2.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/11/27/auto-scrolling-a-textarea-control-in-flex/ --&gt;
&lt;mx:Application name="TextArea_maxVerticalScrollPosition_text"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private var timer:Timer;

            private function init():void {
                timer = new Timer(500);
                timer.addEventListener(TimerEvent.TIMER, onTimer);
                timer.start();
            }

            private function onTimer(evt:TimerEvent):void {
                var now:String = new Date().toTimeString();
                var str:String = "[" + timer.currentCount + "] " + now;
                textArea.text += str + "\\n";
                callLater(autoScrollTextArea, [textArea]);
            }

            private function autoScrollTextArea(target:TextArea):void {
                target.verticalScrollPosition = target.maxVerticalScrollPosition;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:TextArea id="textArea"
            width="200"
            height="160" /&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Auto-scrolling a TextArea control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/11/27/auto-scrolling-a-textarea-control-in-flex/',contentID: 'post-879',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'callLater(),maxVerticalScrollPosition,validateNow(),verticalScrollPosition',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/11/27/auto-scrolling-a-textarea-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Determining a DataGridColumn object&#8217;s current sort order</title>
		<link>http://blog.flexexamples.com/2007/08/23/determining-a-datagridcolumn-objects-current-sort-order/</link>
		<comments>http://blog.flexexamples.com/2007/08/23/determining-a-datagridcolumn-objects-current-sort-order/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 05:34:36 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[DataGridColumn]]></category>
		<category><![CDATA[callLater()]]></category>
		<category><![CDATA[headerRelease]]></category>
		<category><![CDATA[sortDescending]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/23/determining-a-datagridcolumn-objects-current-sort-order/</guid>
		<description><![CDATA[<p>OK, I&#8217;m convinced there is a better way to do this, but so far this is the only solution I&#8217;ve found&#8230;<br /> Any other ideas? Leave em in the comments!</p> <p>Basically the following post shows one possible way of determining the current sort order of a data grid by grabbing the sortDescending property whenever a [...]]]></description>
			<content:encoded><![CDATA[<p>OK, I&#8217;m convinced there is a better way to do this, but so far this is the only solution I&#8217;ve found&#8230;<br />
Any other ideas? Leave em in the comments!</p>
<p>Basically the following post shows one possible way of determining the current sort order of a data grid by grabbing the <code>sortDescending</code> property whenever a user presses on a data grid header.</p>
<p>Full code after the jump.</p>
<p><span id="more-117"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/DataGridColumn_sortDescending_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/08/23/determining-a-datagridcolumn-objects-current-sort-order/ --&gt;
&lt;mx:Application name="DataGridColumn_sortDescending_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.events.DataGridEvent;

            private function doHeaderRelease(evt:DataGridEvent):void {
                var column:DataGridColumn = DataGridColumn(evt.currentTarget.columns[evt.columnIndex]);
                DataGrid(evt.currentTarget).callLater(onCallLater, [column]);
            }

            private function onCallLater(column:DataGridColumn):void {
                columnSortDescending.text = column.dataField + ".sortDescending: " + column.sortDescending;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label id="columnSortDescending" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"
            rowCount="4"
            headerRelease="doHeaderRelease(event)"&gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn id="col1" dataField="label" /&gt;
            &lt;mx:DataGridColumn id="col2" dataField="data" /&gt;
        &lt;/mx:columns&gt;
        &lt;mx:dataProvider&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object data="one" label="User 1" /&gt;
                &lt;mx:Object data="two" label="User 2" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:dataProvider&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/DataGridColumn_sortDescending_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/DataGridColumn_sortDescending_test/bin/main.html" width="100%" height="200"></iframe></p>
<p class="new">April 9, 2009: Actually, here is a much better approach, suggested by my co-worker, and Flex hero, <a href="http://blogs.adobe.com/aharui/">Alex Harui</a>:</p>
<p class="download"><a href="">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/23/determining-a-datagridcolumn-objects-current-sort-order/ --&gt;
&lt;mx:Application name="DataGrid_dataProvider_sort_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

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

            private function init():void {
                try {
                    var s:SortField = Sort(dataGrid.dataProvider.sort).fields[0];
                    lbl.text = "name:" + s.name + ", descending:" + s.descending;
                    lbl.setStyle("color", "black");
                } catch (err:*) {
                    lbl.text = "unsorted";
                    lbl.setStyle("color", "red");
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button id="btn" label="Get sort" click="init();" /&gt;
        &lt;mx:Label id="lbl" fontWeight="bold" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"&gt;
        &lt;mx:dataProvider&gt;
            &lt;mx:Array&gt;
                &lt;mx:Object c1="1.One" c2="1.Two" /&gt;
                &lt;mx:Object c1="2.One" c2="2.Two" /&gt;
                &lt;mx:Object c1="3.One" c2="3.Two" /&gt;
                &lt;mx:Object c1="4.One" c2="4.Two" /&gt;
                &lt;mx:Object c1="5.One" c2="5.Two" /&gt;
                &lt;mx:Object c1="6.One" c2="6.Two" /&gt;
                &lt;mx:Object c1="7.One" c2="7.Two" /&gt;
                &lt;mx:Object c1="8.One" c2="8.Two" /&gt;
            &lt;/mx:Array&gt;
        &lt;/mx:dataProvider&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Determining a DataGridColumn object\&#039;s current sort order on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/23/determining-a-datagridcolumn-objects-current-sort-order/',contentID: 'post-117',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'callLater(),headerRelease,sortDescending',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/08/23/determining-a-datagridcolumn-objects-current-sort-order/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

