<?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>dispatchEvent()™ &#187; Lab</title>
	<atom:link href="http://dispatchevent.org/category/lab/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on the Flash Platform, iOS, Unity, and any other technology we use.</description>
	<lastBuildDate>Tue, 07 Feb 2012 19:22:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The quest for the elusive &#8220;N-gleton&#8221;</title>
		<link>http://dispatchevent.org/mims/the-quest-for-the-elusive-n-gleton/</link>
		<comments>http://dispatchevent.org/mims/the-quest-for-the-elusive-n-gleton/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 06:08:08 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[Lab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips, Tricks, and Hacks]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=638</guid>
		<description><![CDATA[Sure, we&#8217;ve all heard of Singleton, the design pattern that limits the number of instances of a class to one. It&#8217;s a feel good pattern because it&#8217;s easy to use and make us feel smarter in front of our co-workers, &#8230; <a href="http://dispatchevent.org/mims/the-quest-for-the-elusive-n-gleton/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sure, we&#8217;ve all heard of <a href="http://en.wikipedia.org/wiki/Singleton">Singleton</a>, the design pattern that limits the number of instances of a class to one. It&#8217;s a feel good pattern because it&#8217;s easy to use and make us feel smarter in front of our co-workers, even though some would argue that Singletons are just glorified global variables. But for a long time, I have wondered if it would be possible to use the same idea to limit the number of instances to <em>two or more</em> instead of just one. I called this hypothetical pattern an <em>&#8220;N-gleton&#8221;</em>, pronounced &#8220;en-gull-ton&#8221;. (UPDATE: Comments from readers inform me that this is called a &#8220;<a href="http://en.wikipedia.org/wiki/Multiton_pattern">Multiton</a>&#8220;) It may not be possible to make a poly-instance singleton, it may not be good programming practices, I&#8217;m not even sure I can think of a reason why it might be useful, but today, I tried my hand at inventing it and found something else entirely.</p>
<p><span id="more-638"></span></p>
<h3>The Hard Limit approach</h3>
<p>The first attempt I made at the N-gleton was to simply throw an error when the class had been instantiated too many times.</p>
<pre lang="actionscript3">package {
	public class NGletonHardLimit {
		protected static var maxInstances:int = 3;
		protected static var numberOfInstances:int = 0;

		public function NGletonHardLimit() {
			if (numberOfInstances &gt;= maxInstances) {
				throw new Error ("There can only be " + maxInstances + " instances of this class");
			}
			numberOfInstances++;

			// initialize code
		}
	}
}</pre>
<p>This was shortly followed by a slightly more friendly version of the same idea&#8230;</p>
<pre lang="actionscript3">package {
	public class NGletonRequestInstance {
		protected static var maxInstances:int = 3;
		protected static var numberOfInstances:int = 0;

		public static function requestInstance():NGletonRequestInstance {
			if (numberOfInstances &gt;= maxInstances) {
				return null;
			} else {
				return new NGletonRequestInstance(new Key());
			}
		}

		public function NGletonRequestInstance(key:Key) {
			// initialize code
		}
	}
}
class Key {}</pre>
<p>However, I soon realized that this method is quite flawed in its logic. The counter is actually just counting the number of times the <code>requestInstance()</code> method is being called rather than truly controlling the number of instances of the class. It also doesn&#8217;t allow you to release an instance and decrement the instance count. Perhaps something like this would work in C where you can use <code>alloc</code> and <code>dealloc</code> but for Flash, it doesn&#8217;t really make sense. Besides, It doesn&#8217;t really seem useful.</p>
<h3>Cycling through instances</h3>
<p>Next, I tried looping through the same limited set of instances. Each time you request an instance you get a new one until you&#8217;ve reached your limit, then it starts over with the first instance again.</p>
<pre lang="actionscript3">	package
	{
		public class NGletonLoop
		{
			protected static var maxInstances:int = 3;
			protected static var numberOfInstances:int = 0;
			protected static var instances:Array = [];

			public function NGletonLoop(key:Key) {
				// initialize code
			}

			public static function requestInstance():NGletonLoop {
				var n:int = numberOfInstances++ % maxInstances;
				if (instances[n] == null) {
					instances[n] = new NGletonLoop(new Key());
				}
				return NGletonLoop(instances[n]);
			}
		}
	}
	class Key {}</pre>
<p>This approach just felt wrong. In fact, it was totally stupid. There is no way to know what you&#8217;re going to get when you request an instance and it seems like it would be very easy to overwrite data without even knowing it. You still have the problem of the instantiation being counted rather than the actual objects. Besides, it&#8217;s really totally useless.</p>
<p>It was looking like the whole idea of an N-gleton may not really have a practical application. But in the name of theoretical computer science, I chose to press on and try one more idea I had.</p>
<h3>Tracking individual instances</h3>
<p>The previous idea of storing instances in an Array seemed to make some kind of sense to me but it was missing individual control over the instances. So I decided to try using an index to track the instances. I soon realized that a Dictionary that uses objects as keys might give a more useful identifier than an integer. The <code>maximumInstances</code> didn&#8217;t really make sense any more so I took it out. I seemed to be onto something but it wasn&#8217;t really the N-gleton I had imagined, it was something more useful. I called it an <code><em>IndexedObject</em></code>.</p>
<pre lang="actionscript3">	package {
		import flash.utils.Dictionary;

		/**
		 * An example of a class that tracks multiple individual instances by using a dictionary.
		 */
		public class IndexedObject {

			/**
			 * Stores the actual instances of the class.
			 */
			protected static var _instances:Dictionary = new Dictionary(false);

			/**
			 * The identifier that the dictionary uses to reference this instance.
			 */
			public function get id():* { return _id; }
			protected function set id (id:*):void { _id = id; }
			protected var _id:*;  

			/**
			 * Gets an instance of the class. Similar to how a singleton would get the
			 * instance but uses an identifier token to specify which instance to get.
			 */
			public static function getInstance(id:*):IndexedObject {
				if (_instances[id] == null) {
					_instances[id] = new IndexedObject(new Key)
				}
				var instance:IndexedObject = _instances[id] as IndexedObject;
				instance._id = id;
				return instance;
			}

			/**
			 * Returns all of the created instances as an array.
			 */
			public static function get allInstances():Array {
				var array:Array = [];
				var obj:IndexedObject;

				for each (obj in _instances) {
					array.push(obj);
				}
				return array;
			}

			/**
			* Removes an item from the list of instances.
			* Actually, doesn't quite work because an instance referenced by a variable
			* outside of the class could still hold a reference to the deleted instance.
			*/
			public static function deleteObject(id:*):void {
				delete _instances[id];
			}

			/** Just used for testing */
			public var name:String;

			/**
			 * Constructor can't be used by outsided classes.
			 */
			public function IndexedObject(key:Key) {
				// Initialize code
			}
		}
	}
	class Key{}</pre>
<p>So essentially what&#8217;s happening here is the Singleton&#8217;s <code>getInstance()</code> method is being replaced with one that allows you to specify a particular instance. Any class could create new instances or access the same instances provided they had the same id. Here&#8217;s a little demo. I&#8217;m using a <code>name</code> property to show the example.</p>
<pre lang="actionscript3">	var thing:IndexedObject = IndexedObject.getInstance(5);
	thing.name = "thing 5";

	thing = IndexedObject.getInstance("foo");
	thing.name = "thing foo";

	for each (var obj:IndexedObject in IndexedObject.allInstances) {
		trace("IndexedObject.getInstance(",obj.id,") =", IndexedObject.getInstance(obj.id).name);
	}</pre>
<p>Results in:</p>
<p><code>IndexedObject.getInstance( foo ) = thing foo<br />
IndexedObject.getInstance( 5 ) = thing 5</code></p>
<p>Voila. The &#8220;indexed object&#8221;. I think for me the jury is still out on whether this is a good idea. It seems like it might be kind of a hack since it, like Singleton, is essentially just a complicated implementation of global variables but even more so and without Singleton&#8217;s benefits. It also intuitively feels like it could be very useful. Either way, I&#8217;m proud of it.</p>
<p>So what do you think? What would you use this for? Is it a hack? Pattern or anti-pattern?</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/the-quest-for-the-elusive-n-gleton/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AS3 number to hex converter</title>
		<link>http://dispatchevent.org/mims/as3-number-to-hex-converter/</link>
		<comments>http://dispatchevent.org/mims/as3-number-to-hex-converter/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 01:38:44 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[as3lib]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[hexadecimal]]></category>
		<category><![CDATA[hexit]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=618</guid>
		<description><![CDATA[I&#8217;ve been working on some code for converting colors lately and getting quite into bitwise operations. In one of the demos I was making, I needed a quick and easy way to see the results of a color calculation. Of &#8230; <a href="http://dispatchevent.org/mims/as3-number-to-hex-converter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on some code for converting colors lately and getting quite into bitwise operations. In one of the demos I was making, I needed a quick and easy way to see the results of a color calculation. Of course, simply tracing a number, even if it&#8217;s in the format 0xFF, will result in a digital number string &#8220;255&#8243;. I&#8217;ve always been a little stumped about how to do this calculation but I realized that it&#8217;s actually very easy to do with the <a href="http://livedocs.adobe.com/flex/3/langref/operators.html#bitwise_AND">&amp;</a> and <a href="http://livedocs.adobe.com/flex/3/langref/operators.html#bitwise_unsigned_right_shift">&gt;&gt;&gt;</a> bitwise operators.</p>
<p><code><br />
getNumberAsHexString(255); // 0xFF<br />
getNumberAsHexString(0xABCDEF); // 0xABCDEF<br />
getNumberAsHexString(0x00FFCC); // 0xFFCC<br />
getNumberAsHexString(0x00FFCC, 6); // 0x00FFCC - Uses 6 as a minimum number of hexits</code></p>
<p>I&#8217;ve added the code to the <a href="http://as3lib.org">AS3lib</a> asÂ  as a global function. I may move it to a utility class later on. You can <a href="http://code.google.com/p/as3lib/source/browse/trunk/src/org/as3lib/math/getNumberAsHexString.as">view the source</a> on Google Code.</p>
<p>Incidentally, in a moment of bug-fixing frustration, I found <a href="http://kinderas.blogspot.com/2008/01/quicktip-actionscript-3-and-number.html">this article on O.C.A.S.</a> which describes how the same functionality is already built into the <code>toString()</code> method! However, the work isn&#8217;t completely wasted since my version includes the option to show leading zeroes and adds &#8220;<code>0x</code>&#8221; at the front of the result.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/as3-number-to-hex-converter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Flash Player 10 &#8211; 3D Example</title>
		<link>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/</link>
		<comments>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 16:06:27 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash 10]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=431</guid>
		<description><![CDATA[I&#8217;ve tinkered a bit with Flash Player 10. One thing that seems almost funny about the 3D effects of Flash thus far is that very few examples show off actually 3D objects. Most examples I&#8217;ve examined show 2D planes transformed &#8230; <a href="http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tinkered a bit with Flash Player 10. One thing that seems almost funny about the 3D effects of Flash thus far is that very few examples show off actually 3D objects. Most examples I&#8217;ve examined show 2D planes transformed in 3D space. So, I&#8217;ve created a sample 3D cube primitive in AS3 as a convenient example for people who want to get started with their own parsers or drawing tools (etc).</p>
<p><span id="more-431"></span></p>
<p>My current configuration is Mac OS X 5.2 + TextMate 1.5.7 + Flex SDK 4.0.0.3504. I have two shell scripts in place:<a title="txt version of textmate bundle command" href="http://www.calebjohnston.com/storage/scripts/textmate_compile.txt"><br />
</a></p>
<ol>
<li><a title="txt version of mxmlc script" href="http://www.calebjohnston.com/storage/scripts/mxmlc.txt">/usr/bin/mxmlc</a></li>
<li><a title="txt version of textmate bundle command" href="http://www.calebjohnston.com/storage/scripts/textmate_compile.txt">A TextMate run bundle</a> set to a hotkey, &#8220;command + R&#8221;</li>
<li>I&#8217;ve also have my <a title="Flex 4 SDK download" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4">Flex SDK</a> set to the absolute path of: <em>/Developer/SDKs/Flex/4.0.0.3504</em></li>
</ol>
<p>This configuration requires a flex-config.xml in the same directory as the AS3 class file that you&#8217;re compiling. When you run the TextMate script (or something similar in your Terminal shell) it will compile the filename you pass in and default to using a config.xml which acts as a local flex-config.xml file. All of these can be customized as needed.</p>
<p>Example Flash 10 3D cube rotation:<br />
[kml_flashembed movie="http://www.calebjohnston.com/storage/fl10_examples/01_cube_rotation/CubeRotationExample.swf" height="260" width="410" bgcolor="#FFFFFF" /]</p>
<p>Obviously, the above swf won&#8217;t work without Flash player 10 installed.</p>
<p><a title="Flash 10 3D cube rotation example source" href="http://www.calebjohnston.com/storage/fl10_examples/01_cube_rotation.zip">Download the source here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>20 reasons to use KitchenSync for animation and sequencing on your next project</title>
		<link>http://dispatchevent.org/mims/ks-20reasons/</link>
		<comments>http://dispatchevent.org/mims/ks-20reasons/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 05:32:42 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[physics & motion]]></category>
		<category><![CDATA[KitchenSync]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=292</guid>
		<description><![CDATA[Versatility &#8211; Great for tweening animation, yes, but also great for calling functions, disptaching events, playing sounds, controlling MovieClips, and more. Virtually any code can be run at a specific time. In KitchenSync, any event or behaviour that can be &#8230; <a href="http://dispatchevent.org/mims/ks-20reasons/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<ol>
<li><strong>Versatility</strong> &#8211; Great for tweening animation, yes, but also great for calling <a href="http://code.google.com/p/kitchensynclib/wiki/KSFunction">functions</a>, <a href="http://code.google.com/p/kitchensynclib/wiki/KSDispatchEvent">disptaching events</a>, playing <a href="http://code.google.com/p/kitchensynclib/wiki/KSSoundController">sounds</a>, controlling <a href="http://code.google.com/p/kitchensynclib/wiki/KSMovieClipController">MovieClips</a>, and more. Virtually any code can be run at a specific time. In KitchenSync, any event or behaviour that can be sequenced is called an &#8220;<a href="http://code.google.com/p/kitchensynclib/wiki/AbstractAction">action</a>&#8220;.</li>
<li><strong>Advanced sequencing</strong> &#8211; There are several types of <a href="http://code.google.com/p/kitchensynclib/wiki/ActionGroups">action groups</a> designed to meet the real-world sequencing needs of projects.</li>
<li><strong>Interchangeable groups</strong> &#8211; Treats all actions, including groups of actions (like sequences), as the same type of object so they can be interchanged. That means you can nest sequences inside of other sequences.</li>
<li><strong>Video-like <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/AbstractAction.html">controls</a></strong> &#8211; All actions, even groups, have the ability to play, pause, stop, reset, play backwards, loop, and jump to a specific time. Calling one of these functions on a group affects all of the items in the group.</li>
<li><strong>Beyond Penner</strong> &#8211; All the familiar <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/easing/package-detail.html">easing functions</a> are included as well as several original ones like oscillators. An easing utility class has also been added which allows you to create hybrid easing functions.</li>
<p><span id="more-292"></span></p>
<li><strong>Lots of events</strong> &#8211; <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/core/KitchenSyncEvent.html">Events</a> are dispatched throughout the lifetime of an action including when it is started, paused, and completed.</li>
<li><strong>Timeline tweening</strong> &#8211; Set up a complicated animation on the timeline then <a href="http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/">control it using a tween </a>object. From KitchenSync you can change the duration of the animation, the easing function, or play it backwards.</li>
<li><strong>Flexible tweens</strong> &#8211; Tweens are split into two classes. One for timing and easing (<a href="http://code.google.com/p/kitchensynclib/wiki/KSTween">KSTween</a>) and one for controlling values (<a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/tweentarget/ITweenTarget.html">ITweenTarget</a>). This allows you to tween complex values (such as filters, timelines, colors) without using a separate tween class for each application. Factory classes help you create the tween you need.</li>
<li><strong>Tween any property</strong> &#8211; The default tween target, TargetProperty, controls any numeric property of any object, not just a preset list of MovieClip properties. Among other things, that means it can be used in conjunction with other libraries like PaperVision3D.</li>
<li><strong>Customizable actions</strong> &#8211; Actions have many tweakable properties like snapping and synching. Default values can be controlled in a centralized location.</li>
<li><strong>Convenient cloning</strong> &#8211; Any action can be easily cloned and modified with the <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/AbstractAction.html#clone()">clone()</a> method.</li>
<li><strong>Optional Synchronizing</strong> &#8211; All actions have the option of playing back in &#8216;<a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/AbstractAction.html#sync">sync mode</a>&#8216; which will keep your animations in sync with sounds or timers even if the frame rate drops. Or turn this mode off to ensure there are no dropped frames.</li>
<li><strong>Built-in Command queue</strong> &#8211; <a href="http://code.google.com/p/kitchensynclib/wiki/KSSequenceGroup">KSSequenceGroup</a> objects, when combined with <a href="http://code.google.com/p/kitchensynclib/wiki/KSFunction">KSFunction</a> and <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/KSAsynchronousFunction.html">KSAsynchronousFunction</a> objects, can act as a built-in <a href="http://en.wikipedia.org/wiki/Command_queue">command queue</a>. This allows you to build a list of functions and other actions that need to be run in a certain order then execute them all at once.</li>
<li><strong>Easy time parsing</strong> &#8211; <a href="http://code.google.com/p/kitchensynclib/wiki/Timing">Time string parsing</a> makes it incredibly easy to set times using any units you like. Frames, milliseconds, seconds, minutes, hours, even years and abbreviations for each are all supported. Even timecode format (hh:mm:ss;ff) will work.</li>
<li><strong>OOP</strong> &#8211; Super-tight object-oriented design makes the code very easy to extend and customize. Tweens are created as individual objects instead of handled by a static method. Like to name-drop design patterns? We got factory, composite, command, strategy, and of course, singletons to name a few.</li>
<li><strong>Descriptive syntax and lots of documentation</strong> &#8211; Initializing the engine takes one line of code. One more line and your&#8217;re tweening. Exhaustive documentation in the <a href="http://code.google.com/p/kitchensynclib/w/list">wiki</a> and <a href="http://as3lib.org/kitchensync/docs/api/index.html?package-summary.html&amp;all-classes.html">asdocs</a> will help you through the rest.</li>
<li><strong>Speed</strong> &#8211; Tween performance for KitchenSync is competitive with the other major tweening engines like tweener. A very easy to use <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/utils/FrameRateView.html">framerate calculator class</a> is included to help you tweak performance.</li>
<li><strong>Small file size</strong> &#8211; KitchenSync is about 10-20KB (depending on how many classes are used) when compressed.</li>
<li><strong>Tidy</strong> &#8211; Optional <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/AbstractAction.html#autoDelete">automatic deletion</a> of completed tweens helps keep memory managed with minimum effort.</li>
<li>Last but not least, it&#8217;s <strong>Free</strong> &#8211; It&#8217;s free and <a href="http://www.opensource.org/licenses/lgpl-license.php">open source</a>. In other words, you already own it and are free to change it.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/ks-20reasons/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tweening timeline animations with KitchenSync</title>
		<link>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/</link>
		<comments>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 23:31:33 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[physics & motion]]></category>
		<category><![CDATA[Site-seeing]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Videogames]]></category>
		<category><![CDATA[KitchenSync]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=284</guid>
		<description><![CDATA[One of the new features in KitchenSync 1.5 is the ability to tween animations on a MovieClip&#8217;s timeline&#8230; and I&#8217;m not just talking about gotoAndPlay(), I&#8217;m talking about controlling the starting and stopping points, speed, and easing functions of an &#8230; <a href="http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the new features in <a href="http://dispatchevent.org/mims/kitchensync-v1-5/">KitchenSync 1.5</a> is the ability to tween animations on a MovieClip&#8217;s timeline&#8230; and I&#8217;m not just talking about gotoAndPlay(), I&#8217;m talking about controlling the starting and stopping points, speed, and easing functions of an animation on the timeline with code. It does this by incrementally controlling the current frame number of the MovieClip using a <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/KSTween.html">KSTween</a> and a special <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/tweentarget/ITweenTarget.html">ITweenTarget</a> (a class used to control the values of an object) called <a href="http://as3lib.org/kitchensync/docs/api/org/as3lib/kitchensync/action/tweentarget/TimelineController.html"><strong>TimelineController</strong></a>.</p>
<p>Take this FLA animation.</p>
<p><a href="http://dispatchevent.org/wp-content/uploads/2008/07/timelineAnimationStill.png"><img src="http://dispatchevent.org/wp-content/uploads/2008/07/timelineAnimationStill.png" alt="MovieClip animation" /></a></p>
<p>As you can see, there is a simple animation using a guide layer and labels on the key frames.</p>
<p><span id="more-284"></span></p>
<p>The following SWF uses KitchenSync to control the same ball animation. As you can see, the duration and easing functions of the animation can be controlled. You can even animate backwards!</p>
<p><a href="/wp-content/uploads/2008/07/FlashIntegrationTest.swf">See it in action.</a></p>
<p>The source that controls this is here.</p>
<pre lang="actionscript3">package {
	import flash.display.MovieClip;

	import org.as3lib.kitchensync.KitchenSync;
	import org.as3lib.kitchensync.action.*;
	import org.as3lib.kitchensync.action.tweentarget.*;
	import org.as3lib.kitchensync.easing.Bounce;
	import org.as3lib.kitchensync.easing.Cubic;
	import org.as3lib.kitchensync.easing.Linear;
	import org.as3lib.kitchensync.easing.Oscillate;

	/**
	*	Demos the TimelineController which controls the animation of a MovieClip's timeline.
	*/
	public class FlashIntegrationTest extends MovieClip
	{
		protected var test1:MovieClip;

		public function FlashIntegrationTest()
		{
			super();
			// initialize kitchensync.
			KitchenSync.initialize(this, "1.5");

			// add a movieclip from the library
			test1 = MovieClip(new AnimationTest1());
			addChild(test1);

			// define the start and end frame with strings or ints or FrameLabel's
			var startLabel:* = "start";
			var endLabel:* = "end";

			// set up the TimelineController tween target.
			var tweenTarget:TimelineController = new TimelineController(test1, startLabel, endLabel);
			// Animate the ball with a linear ease.
			var tween:KSTween = KSTween.newWithTweenTarget(tweenTarget, "1s", 0, Linear.ease);

			// animate the ball backwards with a bounce tween
			var tween2:KSTween = tween.cloneReversed();
			tween2.duration = "4s";
			tween2.easingFunction = Bounce.easeOut;
			tween2.addTrigger(tween);

			// animate the ball with an oscillator
			var tween3:KSTween = KSTween.newWithTweenTarget(tweenTarget, "10m", "1s", Oscillate.sine);
			tween3.easingMod1 = 0.3;
			tween3.addTrigger(tween2);

			// start the animations
			tween.start();
		}

	}
}</pre>
<p>Pretty cool huh? We&#8217;re creating a new TimelineController and setting the boundaries of the animation then passing it to a new KSTween object. Each of the three tweens use different parameters and are triggered by the end of the one before it.</p>
<p>You can <a href="http://dispatchevent.org/wp-content/uploads/2008/07/timelineControllerDemo.zip">download the entire thing</a> and play around with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/tweening-timeline-animations-with-kitchensync/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>KitchenSync version 1.5 is out!</title>
		<link>http://dispatchevent.org/mims/kitchensync-v1-5/</link>
		<comments>http://dispatchevent.org/mims/kitchensync-v1-5/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 21:58:29 +0000</pubDate>
		<dc:creator>Mims H Wright</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[physics & motion]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[KitchenSync]]></category>
		<category><![CDATA[tween]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=283</guid>
		<description><![CDATA[Odds bodkins! The latest version of what is arguably the best sequencing and tweening system for AS3, KitchenSync, has just been released! I jumped from version 1.2 to 1.5 because this one packed in so many cool features. Features like: &#8230; <a href="http://dispatchevent.org/mims/kitchensync-v1-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://kitchensynclib.googlecode.com/"><img src='http://as3lib.org/kitchensync/docs/img/KSToaster.jpg' alt='KSToaster' class='alignleft' /></a><br />
Odds bodkins! The latest version of what is arguably the best sequencing and tweening system for AS3, <a href="http://kitchensynclib.googlecode.com/">KitchenSync</a>, has just been released! I jumped from version 1.2 to 1.5 because this one packed in so many cool features. Features like:</p>
<ul>
<li>Improved performance (50% faster!)</li>
<li>Filter tweens</li>
<li>Tween MovieClip animations on the timeline</li>
<li>Use a KSSequenceGroup like a function queue</li>
</ul>
<p>I&#8217;ll be posting some demos over the following days. In the meantime, <a href="http://kitchensynclib.googlecode.com/">check it out</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/mims/kitchensync-v1-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

