<?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>David Flatley &#187; animate properties</title>
	<atom:link href="http://www.davidflatley.com/tag/animate-properties/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidflatley.com</link>
	<description>A RIA developer's late night ramblings and other nonsense</description>
	<lastBuildDate>Mon, 22 Mar 2010 15:04:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Flex 4 animate properties</title>
		<link>http://www.davidflatley.com/2010/01/25/flex-4-animate-properties/</link>
		<comments>http://www.davidflatley.com/2010/01/25/flex-4-animate-properties/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:19:54 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Actual RIA info]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[adobe flex 4]]></category>
		<category><![CDATA[animate class]]></category>
		<category><![CDATA[animate properties]]></category>
		<category><![CDATA[gumbo]]></category>

		<guid isPermaLink="false">http://www.davidflatley.com/?p=213</guid>
		<description><![CDATA[I came across a situation while doing a Flex 4 upgrade for an Adobe Developer Center sample app where I wanted to use some the Spark animate properties classes. This is SO cool because it gives you truly granular control over every aspect of a component you want to animate. In the sample I&#8217;m upgrading, [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a situation while doing a Flex 4 upgrade for an <a href="http://www.adobe.com/devnet/flex/"  target="_blank">Adobe Developer Center</a> sample app where I wanted to use some the Spark animate properties classes.</p>
<p>This is SO cool because it gives you truly granular control over every aspect of a component you want to animate. In the sample I&#8217;m upgrading, there is an extended TileGroup component that has three columns and two rows of charts for an enterprise dashboard application. When a user clicks a button to zoom in on any given chart, I wanted to make use of some of the new Spark effects to really create a 3D look and feel quickly (without delving too much into custom layouts). Actually, the layout I made is a custom TileGroup, but I wanted to point out some ways you can use the <a href="http://help.adobe.com/en_US/Flex/4.0/langref/spark/effects/Animate.html"  target="_blank">Animate</a> class to make sweet transitions on any property of a component in your own apps for simple animation, without having to create custom layouts.</p>
<p><span id="more-213"></span></p>
<p>This super simple test was to find out if I could use the Animate class to move the entire TileGroup to a new X,Y and increase its horizontalGap and verticalGap at the same time. In other words, could I use the Animate class to create my whole animation in one shot, truly custom? I watched <a href="http://tv.adobe.com/watch/codedependent/animate-effect-in-flex-4"  target="_blank">Chet Haase  on Adobe TV&#8217;s Codedependent</a> on animating properties, and it worked great, but I needed it running in ActionScript.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td 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;par&quot;</span> duration=<span style="color: #ff0000;">&quot;1000&quot;</span> target=<span style="color: #ff0000;">&quot;{t}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Animate</span> <span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleMotionPath</span> property=<span style="color: #ff0000;">&quot;horizontalGap&quot;</span> </span>
<span style="color: #000000;">									valueFrom=<span style="color: #ff0000;">&quot;15&quot;</span> valueTo=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:SimpleMotionPath</span> property=<span style="color: #ff0000;">&quot;verticalGap&quot;</span> </span>
<span style="color: #000000;">									valueFrom=<span style="color: #ff0000;">&quot;15&quot;</span> valueTo=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Animate</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Move</span> xTo=<span style="color: #ff0000;">&quot;{t.width/2}&quot;</span> yTo=<span style="color: #ff0000;">&quot;{t.height/2}&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>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TileGroup</span> id=<span style="color: #ff0000;">&quot;t&quot;</span> horizontalGap=<span style="color: #ff0000;">&quot;15&quot;</span> verticalGap=<span style="color: #ff0000;">&quot;15&quot;</span> direction=<span style="color: #ff0000;">&quot;ltr&quot;</span> </span>
<span style="color: #000000;">				 width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> click=<span style="color: #ff0000;">&quot;par.play()&quot;</span> label=<span style="color: #ff0000;">&quot;Button One&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> click=<span style="color: #ff0000;">&quot;handleClick(event)&quot;</span> label=<span style="color: #ff0000;">&quot;Button Two&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:TileGroup</span><span style="color: #7400FF;">&gt;</span></span></pre></td></tr></table></div>

<p>The above code is the MXML that worked great for my test, and here&#8217;s the AS3 equivalent:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">Scale</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">Move</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">effects</span>.<span style="color: #006600;">Parallel</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">Animate</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">animation</span>.<span style="color: #006600;">MotionPath</span>;
			<span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">effects</span>.<span style="color: #006600;">animation</span>.<span style="color: #006600;">SimpleMotionPath</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
			<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> handleClick<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> p:Parallel = <span style="color: #000000; font-weight: bold;">new</span> Parallel<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span>;
				p.<span style="color: #0066CC;">duration</span> = <span style="color: #cc66cc;">1000</span>; 
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> s:SimpleMotionPath = <span style="color: #000000; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s.<span style="color: #006600;">valueFrom</span> = t.<span style="color: #006600;">horizontalGap</span>;
				s.<span style="color: #006600;">valueTo</span> = <span style="color: #cc66cc;">200</span>;
				s.<span style="color: #006600;">property</span> = <span style="color: #ff0000;">&quot;horizontalGap&quot;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> s2:SimpleMotionPath = <span style="color: #000000; font-weight: bold;">new</span> SimpleMotionPath<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				s2.<span style="color: #006600;">valueFrom</span> = t.<span style="color: #006600;">verticalGap</span>;
				s2.<span style="color: #006600;">valueTo</span> = <span style="color: #cc66cc;">200</span>;
				s2.<span style="color: #006600;">property</span> = <span style="color: #ff0000;">&quot;verticalGap&quot;</span>; 
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> v:Vector.<span style="color: #66cc66;">&lt;</span>MotionPath<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>MotionPath<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				v.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> s <span style="color: #66cc66;">&#41;</span>;
				v.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> s2 <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> a:Animate = <span style="color: #000000; font-weight: bold;">new</span> Animate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				a.<span style="color: #006600;">motionPaths</span> = v;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> m:Move = <span style="color: #000000; font-weight: bold;">new</span> Move<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				m.<span style="color: #006600;">xTo</span> = t.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
				m.<span style="color: #006600;">yTo</span> = t.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
&nbsp;
				p.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> a <span style="color: #66cc66;">&#41;</span>;
				p.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> m <span style="color: #66cc66;">&#41;</span>;
				p.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Thanks to <a href="http://graphics-geek.blogspot.com/" target="_blank">Chet</a> too for spotting what my tired eyes didn&#8217;t see <img src='http://www.davidflatley.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  sheesh, it&#8217;s been one of those days.</p>
<p>This sample is not very exciting, except for the fact that it gives you the idea how you can animate any property over time. If I wanted to (and I have for my project) animate the x, y, z, width, and height at the same time using the Animate class, you could easily create a very specific animation this way.</p>
<p>For my purposes, I used the <a href="http://help.adobe.com/en_US/Flex/4.0/langref/spark/effects/animation/SimpleMotionPath.html" target="_blank">SimpleMotionPath</a> to specify certain properties to change, and since the Animate class&#8217;s Interpolator is set to NumberInterpolator by default, it worked out great to fill in the steps for the &#8220;tween&#8221; automatically for me. I&#8217;d like to get to the point where I come up with my own Flat-terpolator for some other project one day just to see what I can create, but for now, this worked out fine.</p>
<p>You can download the FXP for this sample and try it out yourself <a href="http://www.davidflatley.com/wp-content/uploads/2010/01/Test.fxp"  target="_blank">here</a>. Once you see how this works, you can imagine the possibilities afforded to Flex 4 that will allow you to make some truly amazing animations. Mine&#8217;s turning out to be pretty cool, but you&#8217;ll have to wait until the ADC releases it <img src='http://www.davidflatley.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  In the meantime, you can get started on <a href="http://www.adobe.com/devnet/flex/samples/flex4_sparkinc/?devcon=f5" target="_blank">this one</a> to catch up on Flex 4 and Flash Builder.</p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/adobe+flex+4' rel='tag' target='_self'>adobe flex 4</a>, <a class='technorati-link' href='http://technorati.com/tag/animate+class' rel='tag' target='_self'>animate class</a>, <a class='technorati-link' href='http://technorati.com/tag/animate+properties' rel='tag' target='_self'>animate properties</a>, <a class='technorati-link' href='http://technorati.com/tag/gumbo' rel='tag' target='_self'>gumbo</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.davidflatley.com/2010/01/25/flex-4-animate-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
