<?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>Easy Flex &#187; Scrolling</title>
	<atom:link href="http://evtimmy.com/tag/scrolling/feed/" rel="self" type="application/rss+xml" />
	<link>http://evtimmy.com</link>
	<description>Evtim on Flex SDK</description>
	<lastBuildDate>Thu, 03 Nov 2011 07:18:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Two Examples of Layout Animations</title>
		<link>http://evtimmy.com/2010/04/two-examples-of-layout-animations/</link>
		<comments>http://evtimmy.com/2010/04/two-examples-of-layout-animations/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 06:42:10 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Custom Layout]]></category>
		<category><![CDATA[Spark Layouts]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Move3D]]></category>
		<category><![CDATA[Rotate3D]]></category>
		<category><![CDATA[Scrolling]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[WheelLayout]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=318</guid>
		<description><![CDATA[A few folks have been asking for the source of my Creating Custom Layouts in Flex 4 talk at the Flash Camp Boston event, and I finally found the time to post it here. My apologies for the delay. Click on the image to go to the demo, right-click and select &#8220;view source&#8221; to get [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://evtimmy.com/wordpress/wp-content/uploads/2010/04/layout-animation/FlickrRIAModified.swf"><img class="alignleft size-thumbnail wp-image-320" title="layout-animation" src="http://evtimmy.com/wordpress/wp-content/uploads/2010/04/layout-animation-150x150.png" alt="layout-animation" width="150" height="150" /></a> A few folks have been asking for the source of my <a href="http://tv.adobe.com/watch/flash-camp-boston/creating-custom-layouts-in-flex-4-">Creating Custom Layouts in Flex 4</a> talk at the Flash Camp Boston event, and I finally found the time to post it here. My apologies for the delay.  Click on the image to go to the demo, right-click and select &#8220;view source&#8221; to get to the goods. <span id="more-318"></span> This is pretty much my old WheelLayout demo, but I added a couple of animations  to make things a little bit slicker:</p>
<ol>
<li>Clicking on any image in the WheelLayout mode will rotate all the elements until the selected item is centered in front. <em>In this animation the layout runs on every frame of the animation.</em></li>
<li>Selecting different layouts from the drop-down will animate the items&#8217; transformation. <em>In this animation the layout is disabled and is not running during the animation.</em></li>
</ol>
<h3>Animating the Scroll Position</h3>
<p>In the first animation I want the selected item to come &#8220;in view&#8221;. In the <em>WheelLayout</em> I&#8217;ve already implemented the standard API that calculates the scroll distance to an item &#8211; <em>getScrollPositionDeltaToElement()</em>. Now in the item renderer of the list &#8211; <em>FlickrThumbnail.mxml</em> &#8211; I detect when the item has been clicked and then create an animation for the scroll position of the parent <em>Group</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> itemrenderer1_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000066; font-weight: bold;">:</span>GroupBase = <span style="color: #004993;">parent</span> <span style="color: #0033ff; font-weight: bold;">as</span> GroupBase<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span> = g<span style="color: #000066; font-weight: bold;">.</span>layout<span style="color: #000066; font-weight: bold;">.</span>getScrollPositionDeltaToElement<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>itemIndex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> startX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = g<span style="color: #000066; font-weight: bold;">.</span>horizontalScrollPosition<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> startY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = g<span style="color: #000066; font-weight: bold;">.</span>verticalScrollPosition<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> anim<span style="color: #000066; font-weight: bold;">:</span>Animate = <span style="color: #0033ff; font-weight: bold;">new</span> Animate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>motionPaths = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #000000;">&#91;</span>
            <span style="color: #0033ff; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;horizontalScrollPosition&quot;</span><span style="color: #000066; font-weight: bold;">,</span> startX<span style="color: #000066; font-weight: bold;">,</span> startX <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>
            <span style="color: #0033ff; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;verticalScrollPosition&quot;</span><span style="color: #000066; font-weight: bold;">,</span> startY<span style="color: #000066; font-weight: bold;">,</span> startY <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #6699cc; font-weight: bold;">var</span> interpolator<span style="color: #000066; font-weight: bold;">:</span>NumberInterpolatorWrapping =
			<span style="color: #0033ff; font-weight: bold;">new</span> NumberInterpolatorWrapping<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> g<span style="color: #000066; font-weight: bold;">.</span>contentWidth <span style="color: #000066; font-weight: bold;">-</span> g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> scrollLength<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = interpolator<span style="color: #000066; font-weight: bold;">.</span>getLength<span style="color: #000000;">&#40;</span>startX<span style="color: #000066; font-weight: bold;">,</span> startX <span style="color: #000066; font-weight: bold;">+</span> p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>interpolator = interpolator<span style="color: #000066; font-weight: bold;">;</span>
        anim<span style="color: #000066; font-weight: bold;">.</span>duration = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">min</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2500</span><span style="color: #000066; font-weight: bold;">,</span> scrollLength <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        anim<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>g<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>One interesting thing to note is that because of the circular nature of the WheelLayout I wanted the animation to interpolate between the values in a wrap-around manner. For example scrolling from the last element to the first element shouldn&#8217;t scroll through any other elements since the first and last elements are visually next to each other. For that reason I implemented a custom interpolator &#8211; <em>NumberInterpolatorWrapping.as</em>.</p>
<h3>Animating Items between Different Layouts</h3>
<p>In this animation I wanted all the elements to move and rotate smoothly when I switch between various layouts. In this animation the start position is defined by the current layout and the end position is defined by the new layout. In-between, while the elements are being animated, they really don&#8217;t belong to any layout. For that reason, I disable the layout of the container for the duration of the animation using the <em>autoLayout </em>property of the parent <em>Group</em>.</p>
<p>For convenience I transition between the layouts using states:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;tile&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;wheel&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;horizontal&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">		dataProvider=<span style="color: #ff0000;">&quot;{photoFeed}&quot;</span></span>
<span style="color: #000000;">		itemRenderer=<span style="color: #ff0000;">&quot;FlickrThumbnail&quot;</span></span>
<span style="color: #000000;">		id=<span style="color: #ff0000;">&quot;theList&quot;</span> useVirtualLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.vertical<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.vertical<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.horizontal<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HorizontalLayout</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.horizontal<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.tile<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TileLayout</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;bottom&quot;</span></span>
<span style="color: #000000;">                                      columnWidth=<span style="color: #ff0000;">&quot;112&quot;</span> rowHeight=<span style="color: #ff0000;">&quot;132&quot;</span></span>
<span style="color: #000000;">				      requestedColumnCount=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.tile<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span>.wheel<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;my:WheelLayout</span> gap=<span style="color: #ff0000;">&quot;20&quot;</span> axisAngle=<span style="color: #ff0000;">&quot;{axisSlider.value}&quot;</span></span>
<span style="color: #000000;">		verticalCenterOffset=<span style="color: #ff0000;">&quot;{offsetSlider.value}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span>.wheel<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:List</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Because the elements could be both moved and/or rotated in 2D or 3D, I use a parallel of both effects:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Parallel</span> id=<span style="color: #ff0000;">&quot;myEffect&quot;</span> effectEnd=<span style="color: #ff0000;">&quot;myEffect_effectEndHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Move</span>3D applyChangesPostLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rotate</span>3D applyChangesPostLayout=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Parallel</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>And finally, when I switch from one layout state to another, I want to run the effect. Now I need to perform the following steps:</p>
<ol>
<li>Make the effect target all of the elements.</li>
<li>Capture the start values (the position and rotation defined by the old layout).</li>
<li>Switch the layout (by changing the state) and call <em>validateNow()</em> so that all elements are positioned and/or rotated by the new layout.</li>
<li>Turn off the <em>autoLayout</em> property so that the new layout doesn&#8217;t interfere with the running effect.</li>
<li>Run the effect. Note that at this point the effect is going to capture the animation end values &#8211; the position/rotation defined by the new layout. I&#8217;ve already captured the start values at step 2, so I&#8217;m all set.</li>
<li>When the effect is done, turn the layout back on.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> animateTo<span style="color: #000000;">&#40;</span>toState<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #009900; font-style: italic;">// Make sure any previous animation is stopped.</span>
    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>myEffect<span style="color: #000066; font-weight: bold;">.</span>isPlaying<span style="color: #000000;">&#41;</span>
        myEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Add targets</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span>targets = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>numElements<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
        myEffect<span style="color: #000066; font-weight: bold;">.</span>targets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>getElementAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Create Transition for all elements</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span>captureStartValues<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Go to the end state</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> fromState<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>currentState<span style="color: #000066; font-weight: bold;">;</span>
    setCurrentState<span style="color: #000000;">&#40;</span>toState<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Validate everything before turning off the layout</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>validateNow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Turn the layout off before running the effect</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>autoLayout = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">// Play the effect</span>
    myEffect<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> myEffect_effectEndHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>EffectEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    theList<span style="color: #000066; font-weight: bold;">.</span>dataGroup<span style="color: #000066; font-weight: bold;">.</span>autoLayout = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note that my demo has one limitation &#8211; I needed to turn off virtual layout so that everything works fine. If I have virtual layout running, I&#8217;m not guaranteed that the old and new layouts will assign the items to the same item renderers.<br />
Click on the image at the top to go to the demo, where you can select &#8220;view source&#8221; from the right-click menu to get the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2010/04/two-examples-of-layout-animations/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>VerticalAlign for VGroup and HorizontalAlign for HGroup</title>
		<link>http://evtimmy.com/2010/01/verticalalign-for-vgroup-and-horizontalalign-for-hgroup/</link>
		<comments>http://evtimmy.com/2010/01/verticalalign-for-vgroup-and-horizontalalign-for-hgroup/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 02:13:49 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[Spark Layouts]]></category>
		<category><![CDATA[alignment]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Scrolling]]></category>
		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=239</guid>
		<description><![CDATA[Recently I checked in the major axis alignment update to VGroup, HGroup, VerticalLayout, HorizontalLayout. It brings parity to the Flex 4 Spark layouts relative to the MX containers HBox and VBox that are well known from previous versions of Flex (and have had those alignment options for long time now). Now VGroup and VerticalLayout have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://evtimmy.com/wordpress/wp-content/uploads/2010/01/majoraxisalignment.swf"><img class="alignleft size-thumbnail wp-image-240" title="majoraxisalignment" src="http://evtimmy.com/wordpress/wp-content/uploads/2010/01/majoraxisalignment-150x150.png" alt="majoraxisalignment" width="150" height="150" /></a> Recently I checked in the major axis alignment update to <em>VGroup</em>, <em>HGroup</em>, <em>VerticalLayout</em>, <em>HorizontalLayout</em>. It brings parity to the Flex 4 Spark layouts relative to the MX containers <em>HBox</em> and <em>VBox </em>that are well known from previous versions of Flex (and have had those alignment options for long time now). <span id="more-239"></span></p>
<p>Now <em>VGroup </em>and <em>VerticalLayout </em>have a &#8220;<em>verticalAlign</em>&#8221; property with the three supported values of &#8220;<em>top</em>&#8220;, &#8220;<em>middle</em>&#8220;, &#8220;<em>bottom</em>&#8220;.  Accordingly <em>HGroup </em>and <em>HorizontalLayout </em>get a &#8220;<em>horizontalAlign</em>&#8221; property with the supported values of &#8220;<em>left</em>&#8220;, &#8220;<em>center</em>&#8221; and &#8220;<em>right</em>&#8220;.  The alignment modes work for the layouts with and without virtualization enabled.<br />
An important difference to note is that when &#8220;<em>clipAndEnableScrolling</em>&#8221; is set to &#8220;<em>true</em>&#8221; and the containers are scrolling (the content is bigger than the container), the Spark layouts ensure that the entire content can be scrolled in view by internally reverting to the &#8220;<em>top</em>&#8220;/&#8221;<em>left</em>&#8221; alignment respectively.</p>
<p>When playing with the attached sample, you&#8217;ll notice difference between the clipping and the non-clipping containers when scrolling is in effect (drag the slider left to force smaller height for the containers).</p>
<p>The sample was compiled with SDK version 4.0.0.13553, source: <a href="http://evtimmy.com/wordpress/wp-content/uploads/2010/01/majoraxisalignment.mxml">MajorAxisAlignment.mxml</a></p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2010/01/verticalalign-for-vgroup-and-horizontalalign-for-hgroup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FlowLayout Part 2 &#8211; Gap, VerticalAlign and Scrolling</title>
		<link>http://evtimmy.com/2009/06/flowlayout-part-2-gap-verticalalign-and-scrolling/</link>
		<comments>http://evtimmy.com/2009/06/flowlayout-part-2-gap-verticalalign-and-scrolling/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 06:53:39 +0000</pubDate>
		<dc:creator>Evtim</dc:creator>
				<category><![CDATA[Custom Layout]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Scrolling]]></category>
		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://evtimmy.com/?p=80</guid>
		<description><![CDATA[In part one here, the FlowLayout had really basic functionality.  I decided to demonstrate how to add layout properties to the custom Spark layouts and how to enable scrolling.]]></description>
			<content:encoded><![CDATA[<p>In part one <a href="http://evtimmy.com/?p=3">here</a>, the FlowLayout had really basic functionality.  I decided to demonstrate how to add layout properties to the custom Spark layouts and how to enable scrolling.</p>
<p><span id="more-80"></span>Let me show off the end result first:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="400" height="300" align="center">
      <param name="movie" value="http://evtimmy.com/wordpress/wp-content/uploads/2009/06/flowtest-props-and-scrolling2.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://evtimmy.com/wordpress/wp-content/uploads/2009/06/flowtest-props-and-scrolling2.swf" width="400" height="300" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>And the source code is available <a href="http://evtimmy.com/wordpress/wp-content/uploads/2009/10/flowtestpropsandscrolling2.zip">here</a>.</p>
<p><em>Update: The source has been updated to compile with Flash Builder / Flex SDK beta 2. I also added a horizontalAlign property, just because I can =)</em></p>
<h3>Adding a Layout Property</h3>
<p>I want to implement two properties &#8211; a horizontalGap for between the elements within a row, and verticalAlign which will control how the elements within the row are aligned. For the latter, I&#8217;ll have &#8220;top&#8221;, &#8220;middle&#8221; and &#8220;bottom&#8221; as options, and of course I&#8217;ll have to beef up the FlowLayout to support elements with various heights.</p>
<p>I&#8217;ll add the properties directly to the FlowLayout class. When the value changes, I need to invalidate the container which will cause the layout to run its updateDisplayList() and at that point I&#8217;ll take into account the new values:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">    <span style="color: #009900; font-style: italic;">//---------------------------------------------------------------</span>
    <span style="color: #009900; font-style: italic;">//  horizontalGap</span>
    <span style="color: #009900; font-style: italic;">//---------------------------------------------------------------</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _horizontalGap<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> horizontalGap<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
        _horizontalGap = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// We must invalidate the layout</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> layoutTarget<span style="color: #000066; font-weight: bold;">:</span>GroupBase = <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>layoutTarget<span style="color: #000000;">&#41;</span>
            layoutTarget<span style="color: #000066; font-weight: bold;">.</span>invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//---------------------------------------------------------------</span>
    <span style="color: #009900; font-style: italic;">//  verticalAlign</span>
    <span style="color: #009900; font-style: italic;">//---------------------------------------------------------------</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _verticalAlign<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;bottom&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> verticalAlign<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
        _verticalAlign = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// We must invalidate the layout</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> layoutTarget<span style="color: #000066; font-weight: bold;">:</span>GroupBase = <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>layoutTarget<span style="color: #000000;">&#41;</span>
            layoutTarget<span style="color: #000066; font-weight: bold;">.</span>invalidateDisplayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Then I will add a drop-down and a slider in the flowTest.mxml to configure the the properties like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;">    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The slider to control the horizontal gap --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HSlider</span> id=<span style="color: #ff0000;">&quot;hGapSlider&quot;</span> minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;50&quot;</span></span>
<span style="color: #000000;">                         value=<span style="color: #ff0000;">&quot;10&quot;</span> liveDragging=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The drop-down to select vertical alignment --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:DropDownList</span> id=<span style="color: #ff0000;">&quot;vAlign&quot;</span> requiresSelection=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:String</span><span style="color: #7400FF;">&gt;</span></span>bottom<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:String</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:String</span><span style="color: #7400FF;">&gt;</span></span>middle<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:String</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:String</span><span style="color: #7400FF;">&gt;</span></span>top<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:String</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:ArrayCollection</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:DropDownList</span><span style="color: #7400FF;">&gt;</span></span>                         
&nbsp;
    <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- A Spark List --&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> id=<span style="color: #ff0000;">&quot;list1&quot;</span> width=<span style="color: #ff0000;">&quot;{widthSlider.value}&quot;</span></span>
<span style="color: #000000;">            selectedIndex=<span style="color: #ff0000;">&quot;7&quot;</span></span>
<span style="color: #000000;">            dataProvider=<span style="color: #ff0000;">&quot;{new ArrayCollection(</span>
<span style="color: #000000;">            'The quick fox jumped over the lazy sleepy\n\dog'.split(' '))}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Configure the layout to be the FlowLayout --&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;my:FlowLayout</span><span style="color: #cc66cc;">1</span> verticalAlign=<span style="color: #ff0000;">&quot;{vAlign.selectedItem}&quot;</span></span>
<span style="color: #000000;">                            horizontalGap=<span style="color: #ff0000;">&quot;{hGapSlider.value}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:List</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>Then the harder part &#8211; actually implementing the support for these properties in the FlowLayout&#8217;s updateDisplayList() method.  Since I&#8217;ll need to know the row height before I can decide how to position the elements, I&#8217;ll have to replace my original loop with a little more complicated code, something along the lines of:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">        <span style="color: #009900; font-style: italic;">// loop through the elements</span>
        <span style="color: #009900; font-style: italic;">// while we can start a new row</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> rowStart<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>rowStart <span style="color: #000066; font-weight: bold;">&lt;</span> count<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #009900; font-style: italic;">// The row always contains the start element</span>
            element = layoutTarget<span style="color: #000066; font-weight: bold;">.</span>getElementAt<span style="color: #000000;">&#40;</span>rowStart<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> rowWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = element<span style="color: #000066; font-weight: bold;">.</span>getPreferredBoundsWidth<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> rowHeight<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> =  element<span style="color: #000066; font-weight: bold;">.</span>getPreferredBoundsHeight<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Find the end of the current row</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> rowEnd<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = rowStart<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>rowEnd <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">&lt;</span> count<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                element = layoutTarget<span style="color: #000066; font-weight: bold;">.</span>getElementAt<span style="color: #000000;">&#40;</span>rowEnd <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">// Since we haven't resized the element just yet, get its preferred size</span>
                elementWidth = element<span style="color: #000066; font-weight: bold;">.</span>getPreferredBoundsWidth<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                elementHeight = element<span style="color: #000066; font-weight: bold;">.</span>getPreferredBoundsHeight<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">// Can we add one more element to this row?</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rowWidth <span style="color: #000066; font-weight: bold;">+</span> hGap <span style="color: #000066; font-weight: bold;">+</span> elementWidth <span style="color: #000066; font-weight: bold;">&gt;</span> containerWidth<span style="color: #000000;">&#41;</span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                rowWidth <span style="color: #000066; font-weight: bold;">+</span>= hGap <span style="color: #000066; font-weight: bold;">+</span> elementWidth<span style="color: #000066; font-weight: bold;">;</span>
                rowHeight = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>rowHeight<span style="color: #000066; font-weight: bold;">,</span> elementHeight<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                rowEnd<span style="color: #000066; font-weight: bold;">++;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Layout all the elements within the row</span>
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = rowStart<span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span>= rowEnd<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                element = layoutTarget<span style="color: #000066; font-weight: bold;">.</span>getElementAt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000066; font-weight: bold;">...</span>
                <span style="color: #009900; font-style: italic;">// Position the element</span>
                element<span style="color: #000066; font-weight: bold;">.</span>setLayoutBoundsPosition<span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> elementY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Next row will start with the first element after the current row's end</span>
            rowStart = rowEnd <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Update the position to the beginning of the row</span>
            <span style="color: #000066; font-weight: bold;">...</span>
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>Enabling Scrolling</h3>
<p>Now I&#8217;m almost done, but I want the FlowLayout to be scrollable. In theory this would mean that I need do the following steps:</p>
<ol>
<li> Add scroll-bars.</li>
<li>Hook up the scroll-bars with the layout&#8217;s horizontalScrollPosition and verticalScrollPosition properties.</li>
<li>Calculate the ranges for the scroll-bars and keep them in sync whenever the values change.</li>
</ol>
<p>In practice, I can save a lot of work by using a ready stock Spark component &#8211; the Scroller. Without going into too much details, the Scroller can wrap a container and automatically put up scroll-bars, keeping everything in sync with the container&#8217;s layout.  And since in my flowTest.mxml I&#8217;m using a List, the Scroller is already in there!!! It&#8217;s a part of the List default skin <img src='http://evtimmy.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Now all that&#8217;s left to do for me is actually calculate the ranges for the scroll bars. This is basically the total width and height of the scrollable area of the container a.k.a. the &#8220;content size&#8221;.</p>
<p>Calculating the content size is easy enough &#8211; I&#8217;ll just find the maximum extents of all the children while I&#8217;m resizing and arranging them in the FlowLayout&#8217;s updateDisplayList(). At the very end of that method I&#8217;ll set the updated content size like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>144
145
146
147
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;">        <span style="color: #009900; font-style: italic;">// Set the content size which determines the scrolling limits</span>
        <span style="color: #009900; font-style: italic;">// and is used by the Scroller to calculate whether to show up</span>
        <span style="color: #009900; font-style: italic;">// the scrollbars when the the scroll policy is set to &quot;auto&quot;</span>
        layoutTarget<span style="color: #000066; font-weight: bold;">.</span>setContentSize<span style="color: #000000;">&#40;</span>maxRowWidth<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://evtimmy.com/2009/06/flowlayout-part-2-gap-verticalalign-and-scrolling/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

