<?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>The efnx code blog. &#187; MovieClip</title>
	<atom:link href="http://efnx.com/tag/movieclip/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Wed, 18 Jan 2012 20:48:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>AS3 Animation class to replace MovieClip</title>
		<link>http://efnx.com/as3-animation-class-to-replace-movieclip/</link>
		<comments>http://efnx.com/as3-animation-class-to-replace-movieclip/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 20:14:42 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[FPS]]></category>
		<category><![CDATA[MovieClip]]></category>
		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=10</guid>
		<description><![CDATA[Okay, let me start by saying that I HATE importing resources into fla&#8217;s. When I first learned Flash [AS2] it wasn&#8217;t an issue. Now with AS3 and the necessity of classes my coding style has changed and I really, really like keeping things as separated into classes as possible. The Problem With MovieClips When attempting [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, let me start by saying that I HATE importing resources into fla&#8217;s. When I first learned Flash [AS2] it wasn&#8217;t an issue. Now with AS3 and the necessity of classes my coding style has changed and I really, really like keeping things as separated into classes as possible. </p>
<p><strong>The Problem With MovieClips</strong><br />
When attempting to program button classes I ran into this wall: Flash&#8217;s MovieClip is the only appropriate class object to use for animation. It&#8217;s great for placing images in your timeline to form moving pictures and placing Actionscript on certain frames makes directing the clip around really easy. But what about when you have to make MovieClips dynamically and add code to certain frames inside that clip, without using the GUI? MovieClip doesn&#8217;t support dynamically adding frames, or functions or Bitmaps to certain frames. This sucks. Why Adobe did this I do not know &#8211; so I wrote a class that DOES WHAT I WANT [and maybe you too].</p>
<p><strong>Usage</strong><br />
Animation takes three parameters, which are all optional: numFrames:int = 1 width:int = 0, and height:int = 0. These params just initiate the object.</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/*<br />
* &nbsp; &nbsp; blog.efnx.com:Animation Example<br />
*/</span><br />
<br />
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">efnx</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Animation</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//import the class</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> character:Animation = <span style="color: #000000; font-weight: bold;">new</span> Animation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//object sets numFrames, width and height to 1, 0 and 0</span></div></div>
<p>After making the object you have to append the pictures to certain frames using the appendBitmapData function:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span>theFrame:<span style="color: #0066CC;">int</span>, bitmapData:BitmapData<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>What this does is take the BitmapData and attach a function to the given frame that replaces the Animation&#8217;s default BitmapData with yours upon execution of that frame.<br />
Doing this achieves the same effect as dragging a bitmap onto the stage in a MovieClip keyframe.</p>
<p>I wrote the class keeping in mind that someone may want to use it not for animation but sequential code execution, so frames can be created and functions attached to each frame without any graphics associated. The function used to add [or append] other functions to a certain frame is</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp;appendFrameScript<span style="color: #66cc66;">&#40;</span>theFrame:<span style="color: #0066CC;">int</span>, theFunction:<span style="color: #000000; font-weight: bold;">Function</span>, <span style="color: #66cc66;">&#91;</span>testing:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>theFrame is the frame you&#8217;d like to add a function to, theFunction is the function to be added and testing tells the class whether or not to print debug info.</p>
<p>After adding frames and bitmaps and all that Animation can be controlled using familiar MovieClip methods like gotoAndPlay(), gotoAndStop(), go(), stop() and properties like currentFrame and totalFrames, as well as some others &#8211; bmd [the current frames BitmapData], bmdArray [an array of all frames BitmapData] and cool functions like customFps(fps:int) which set a custom playback rate denoted in number of frames per second [fps:int] and accelerateFps(desiredFps:int, numberFrames:int) which accelerates the playback delay from the current FPS to the desired FPS in numberFrames frames. accelerateFps is still a little buggy, feel free to nice it up!</p>
<p><strong>Last Words</strong><br />
Animation doesn&#8217;t automatically loop your animation [since I usually don't need it to], so to really mimic a MovieClip you&#8217;d have to write a function incorporating gotoAndPlay(1) and then attach the function to the frame you&#8217;d like to loop your clip at:</p>
<div class="codecolorer-container actionscript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> character:Animation = <span style="color: #000000; font-weight: bold;">new</span> Animation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//initiate object</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, firstBitmapData<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//add BitmapData</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendBitmapData</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>, secondBitmapData<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #006600;">appendFrameScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>, repeat<span style="color: #66cc66;">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//append repeat function</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> repeat<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">//repeat function</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;character.<span style="color: #0066CC;">gotoAndPlay</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Hope this class helps some of you out. Feel free to let me know what needs improving and comment if you like it!</p>
<p><strong>Source</strong><br />
<a href='http://blog.efnx.com/wp-content/uploads/2007/10/blogefnxcom-animation.zip' title='Animation Class Source Code'>Animation Class Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/as3-animation-class-to-replace-movieclip/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

