<?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>opentransmission &#187; Animation</title>
	<atom:link href="http://opentransmission.com/category/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://opentransmission.com</link>
	<description>Interactive Design, Development and Animation by Eric Cohen</description>
	<lastBuildDate>Thu, 29 Apr 2010 01:29:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tweener Text Swap Animation</title>
		<link>http://opentransmission.com/2010/01/tweener-text-swap-animation/</link>
		<comments>http://opentransmission.com/2010/01/tweener-text-swap-animation/#comments</comments>
		<pubDate>01/10</pubDate>
		<dc:creator>Eric Cohen</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Animation]]></category>

		<guid isPermaLink="false">http://escohen.com/?p=17</guid>
		/*<description><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_TweenerSwap_1220632698"
			class="flashmovie"
			width="665"
			height="70">
	<param name="movie" value="http://www.opentransmission.com/shared/flash/TweenerSwap.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.opentransmission.com/shared/flash/TweenerSwap.swf"
			name="fm_TweenerSwap_1220632698"
			width="665"
			height="70">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>I came across this little trick and think it&#8217;s a great way to swap out copy in an easy and unique way. Using one of Tweener&#8217;s Textshortcut properties, you can change the copy in a textfield by tweening between strings. Typically I try to use native Flash tweening in these prototypes, [...]]]></description>*/
			<content:encoded><![CDATA[
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_TweenerSwap_946284872"
			class="flashmovie"
			width="665"
			height="70">
	<param name="movie" value="http://www.opentransmission.com/shared/flash/TweenerSwap.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.opentransmission.com/shared/flash/TweenerSwap.swf"
			name="fm_TweenerSwap_946284872"
			width="665"
			height="70">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>I came across this little trick and think it&#8217;s a great way to swap out copy in an easy and unique way. Using one of Tweener&#8217;s Textshortcut properties, you can change the copy in a textfield by tweening between strings. Typically I try to use native Flash tweening in these prototypes, but Tweener has this transition not found in Flash&#8217;s framework. <span id="more-17"></span><br />
<br />
Here, an event listener waits for a button to be clicked. Depending on which button is clicked, it sets the string to new copy and changes the size of the sprite behind it.  For this to work, download the newest Tweener AS3 classes from <a href ="http://code.google.com/p/tweener/" target="_blank">http://code.google.com/p/tweener/</a> and include it in your project with the import statements in the first few lines of the TweenerSwap class.<br />
<br />
<a class="download" href="http://www.opentransmission.com/downloads/TweenerSwap.zip", target"_blank"><b>Download Source</b></a></p>
<h5>Main.as</h5>

<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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> caurina.<span style="color: #000000;">transitions</span>.<span style="color: #000000;">Tweener</span>;
	<span style="color: #0066CC;">import</span> caurina.<span style="color: #000000;">transitions</span>.<span style="color: #000000;">properties</span>.<span style="color: #000000;">TextShortcuts</span>;
	TextShortcuts.<span style="color: #000000;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #000000;">display</span>.<span style="color: #000000;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #000000;">events</span>.<span style="color: #000000;">MouseEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextFormat</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #000000;">TextFormatAlign</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #000000;">AntiAliasType</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #000000;">controls</span>.<span style="color: #0066CC;">Button</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TweenerSwap <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> btn1:<span style="color: #0066CC;">Button</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> btn2:<span style="color: #0066CC;">Button</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> btn3:<span style="color: #0066CC;">Button</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> squContainer:Sprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> square:Sprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> tF:<span style="color: #0066CC;">TextField</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> textStr:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> squWidth:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> squHeight:<span style="color: #0066CC;">Number</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TweenerSwap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			format<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			squContainer = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>squContainer<span style="color: #66cc66;">&#41;</span>;
			squContainer.<span style="color: #000000;">alpha</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
			square = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			squContainer.<span style="color: #000000;">addChild</span><span style="color: #66cc66;">&#40;</span>square<span style="color: #66cc66;">&#41;</span>;
			square.<span style="color: #000000;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFF0000, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
			square.<span style="color: #000000;">graphics</span>.<span style="color: #000000;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
			square.<span style="color: #000000;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> fmt:<span style="color: #0066CC;">TextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			fmt.<span style="color: #0066CC;">font</span>=<span style="color: #ff0000;">&quot;Arial&quot;</span>;
			fmt.<span style="color: #0066CC;">size</span>=<span style="color: #cc66cc;">12</span>;
			fmt.<span style="color: #0066CC;">color</span>= 0xCCCCCC;
			fmt.<span style="color: #0066CC;">leading</span>=<span style="color: #cc66cc;">4</span>;
			fmt.<span style="color: #0066CC;">align</span> = TextFormatAlign.<span style="color: #000000;">CENTER</span>;
&nbsp;
			tF = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			tF.<span style="color: #0066CC;">multiline</span>=<span style="color: #000000; font-weight: bold;">true</span>;
			tF.<span style="color: #0066CC;">wordWrap</span>=<span style="color: #000000; font-weight: bold;">true</span>;
			tF.<span style="color: #0066CC;">width</span>=<span style="color: #cc66cc;">300</span>;
			tF.<span style="color: #0066CC;">selectable</span>=<span style="color: #000000; font-weight: bold;">false</span>;
			tF.<span style="color: #000000;">defaultTextFormat</span>=fmt;
			tF.<span style="color: #000000;">antiAliasType</span> = AntiAliasType.<span style="color: #000000;">ADVANCED</span>;
			tF.<span style="color: #000000;">mouseEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			squContainer.<span style="color: #000000;">addChild</span><span style="color: #66cc66;">&#40;</span>tF<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> container:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>container<span style="color: #66cc66;">&#41;</span>;
			container.<span style="color: #000000;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #000000;">MOUSE_DOWN</span>, swapText, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			btn1 = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			btn1.<span style="color: #000000;">label</span> = <span style="color: #ff0000;">&quot;String 1&quot;</span>;
			container.<span style="color: #000000;">addChild</span><span style="color: #66cc66;">&#40;</span>btn1<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;btn1&quot;</span>;
&nbsp;
			btn2 = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			btn2.<span style="color: #000000;">label</span> = <span style="color: #ff0000;">&quot;String 2&quot;</span>;
			container.<span style="color: #000000;">addChild</span><span style="color: #66cc66;">&#40;</span>btn2<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;btn2&quot;</span>;
&nbsp;
			btn3 = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Button</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			btn3.<span style="color: #000000;">label</span> = <span style="color: #ff0000;">&quot;String 3&quot;</span>;
			container.<span style="color: #000000;">addChild</span><span style="color: #66cc66;">&#40;</span>btn3<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">name</span> = <span style="color: #ff0000;">&quot;btn3&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> format<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			btn1.<span style="color: #000000;">y</span> = <span style="color: #cc66cc;">0</span>;
			btn2.<span style="color: #000000;">y</span> = <span style="color: #cc66cc;">24</span>;
			btn3.<span style="color: #000000;">y</span> = <span style="color: #cc66cc;">48</span>;
&nbsp;
			squContainer.<span style="color: #000000;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #000000;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> swapText<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;btn3&quot;</span>:
				textStr = <span style="color: #ff0000;">&quot;As we must account for every idle word, so must we account for every idle silence.&quot;</span>;
				squWidth = <span style="color: #cc66cc;">180</span>;
				squHeight = <span style="color: #cc66cc;">60</span>;
				<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;btn2&quot;</span>:
				textStr = <span style="color: #ff0000;">&quot;If you would not be forgotten as soon as you are dead, either write something worth reading or do things worth writing.&quot;</span>;
				squWidth = <span style="color: #cc66cc;">350</span>;
				squHeight = <span style="color: #cc66cc;">40</span>;
				<span style="color: #b1b100;">break</span>;
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;btn1&quot;</span>:
				textStr = <span style="color: #ff0000;">&quot;A great empire, like a great cake, is most easily diminished at the edges.&quot;</span>;
				squWidth = <span style="color: #cc66cc;">410</span>;
				squHeight = <span style="color: #cc66cc;">20</span>;
				<span style="color: #b1b100;">break</span>;
				<span style="color: #000000; font-weight: bold;">default</span>:
				<span style="color: #b1b100;">break</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			Tweener.<span style="color: #000000;">addTween</span><span style="color: #66cc66;">&#40;</span>squContainer, <span style="color: #66cc66;">&#123;</span>x:<span style="color: #0066CC;">stage</span>.<span style="color: #000000;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> - squWidth<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> + <span style="color: #cc66cc;">50</span>, y:<span style="color: #0066CC;">stage</span>.<span style="color: #000000;">stageHeight</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> - squHeight<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>, alpha:<span style="color: #cc66cc;">1</span>, <span style="color: #0066CC;">time</span>:<span style="color: #cc66cc;">1</span>, delay:<span style="color: #cc66cc;">0</span>, transition:<span style="color: #ff0000;">&quot;easeInOutQuart&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
			Tweener.<span style="color: #000000;">addTween</span><span style="color: #66cc66;">&#40;</span>square, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">width</span>:squWidth, <span style="color: #0066CC;">height</span>:squHeight, <span style="color: #0066CC;">time</span>:<span style="color: #cc66cc;">1</span>, delay:<span style="color: #cc66cc;">0</span>, transition:<span style="color: #ff0000;">&quot;easeInOutQuart&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
			Tweener.<span style="color: #000000;">addTween</span><span style="color: #66cc66;">&#40;</span>tF, <span style="color: #66cc66;">&#123;</span>_text:textStr, <span style="color: #0066CC;">width</span>:squWidth, <span style="color: #0066CC;">height</span>:squHeight, <span style="color: #0066CC;">time</span>:<span style="color: #cc66cc;">1</span>, delay:<span style="color: #cc66cc;">0</span>, transition:<span style="color: #ff0000;">&quot;easeInOutQuart&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://opentransmission.com/2010/01/tweener-text-swap-animation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
