<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Flash For Learning &#187; Animation</title>
	<atom:link href="http://flashforlearning.com/category/animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashforlearning.com</link>
	<description>Knowledge Management &#62; Learning Strategy &#62; E-Learning &#62; Flash</description>
	<pubDate>Mon, 15 Sep 2008 03:45:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
		<!-- podcast_generator="podPress/8.8" -->
		<copyright>&#xA9; </copyright>
		<managingEditor>aaron.silvers@gmail.com ()</managingEditor>
		<webMaster>aaron.silvers@gmail.com()</webMaster>
		<category></category>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary>Knowledge Management gt; Learning Strategy gt; E-Learning gt; Flash</itunes:summary>
		<itunes:author></itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name></itunes:name>
			<itunes:email>aaron.silvers@gmail.com</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://flashforlearning.com/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://flashforlearning.com/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>Flash For Learning</title>
			<link>http://flashforlearning.com</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Processing</title>
		<link>http://flashforlearning.com/2005/04/processing/</link>
		<comments>http://flashforlearning.com/2005/04/processing/#comments</comments>
		<pubDate>Thu, 28 Apr 2005 21:35:15 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[Animation]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=12</guid>
		<description><![CDATA[<p>Holy crap is this cool!</p>
]]></description>
			<content:encoded><![CDATA[<p>Holy crap is <a href="http://processing.org/index.html">this</a> cool!</p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/processing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Asteroids 2.04: When Things Collide</title>
		<link>http://flashforlearning.com/2005/04/asteroids-204-when-things-collide/</link>
		<comments>http://flashforlearning.com/2005/04/asteroids-204-when-things-collide/#comments</comments>
		<pubDate>Mon, 25 Apr 2005 03:23:16 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[Animation]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=9</guid>
		<description><![CDATA[<p>I was away learning about Knowledge Management this week, which will occupy several blog entries as what I learned from this conference experience relates directly to the purpose of this site.</p>

<p>But, I also wanted to let you know how easy it is to use classes that other people author.</p>
]]></description>
			<content:encoded><![CDATA[<p>I was away learning about Knowledge Management this week, which will occupy several blog entries as what I learned from this conference experience relates directly to the purpose of this site.</p>

<p>But, I also wanted to let you know how easy it is to use classes that other people author.</p>

<p>As you can see, I have collision detection working.  And I barely wrote any code.  In fact the class that runs this is directly from Grant Skinner, who released his <a href="http://www.gskinner.com/blog/archives/2005/02/source_code_gri.html">ProxmityManager</a> class on his site back in February.  After reading <a href="http://www.waxpraxis.org/coding/18/back-to-school-and-lots-of-little-squares">Branden Hall&#8217;s blog</a> using the same methodology as far as dividing the screen into a grid, and then, when the ship is in a particular block, it checks the neighboring blocks for asteroids.</p>

<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="150">
  <param name="movie" value="http://flashforlearning.com/files/Asteroids_04.swf">
  </param><param name=quality value=high>
  <embed src="http://flashforlearning.com/files/Asteroids_04.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="150"></embed>
</param></object></p>

<p><a href="http://flashforlearning.com/files/Asteroids_04.zip">Download the source files</a> for yourself and check out Grant&#8217;s and Branden&#8217;s blogs for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/asteroids-204-when-things-collide/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Asteroids 2.03: New Asteroid Shapes</title>
		<link>http://flashforlearning.com/2005/04/asteroids-203-new-asteroid-shapes/</link>
		<comments>http://flashforlearning.com/2005/04/asteroids-203-new-asteroid-shapes/#comments</comments>
		<pubDate>Mon, 18 Apr 2005 02:14:26 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[Animation]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=8</guid>
		<description><![CDATA[<p>I read several articles online.  Looked at academic research on a <a href="http://www.cosy.sbg.ac.at/~held/projects/rpg/rpg.html">Random Polygon Generator</a>.  The algorithms were mind boggling.  I e-mailed some very smart ActionScript programmers for some help.  None came (at least by the time of this writing).</p>

<p>Then it occurred to me... can't I just rotate similar-sized squares and triangles appearing randomly to produce a randomly shaped polygon?  Bet your ass I could :)</p>
]]></description>
			<content:encoded><![CDATA[<p>So I didn&#8217;t expand on the interaction between the ship and the asteroids.  Instead, I tooled around all weekend trying to create randomly shaped polygons to use for the asteroids.  This is something I wanted to do in the original build and never took the time to concentrate on the problem.</p>

<p>I read several articles online.  Looked at academic research on a <a href="http://www.cosy.sbg.ac.at/~held/projects/rpg/rpg.html">Random Polygon Generator</a>.  The algorithms were mind boggling.  I e-mailed some very smart ActionScript programmers for some help.  None came (at least by the time of this writing).</p>

<p>Then it occurred to me&#8230; can&#8217;t I just rotate similar-sized squares and triangles appearing randomly to produce a randomly shaped polygon?  Bet your ass I could <img src='http://flashforlearning.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="150">
  <param name="movie" value="http://flashforlearning.com/files/Asteroids_03.swf">
  </param><param name=quality value=high>
  <embed src="http://flashforlearning.com/files/Asteroids_03.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="150"></embed>
</param></object></p>

<p><a href="http://flashforlearning.com/files/Asteroids_03.zip">Download the source files</a>.</p>

<p>So this release marks two changes that are related.  One is the obvious &#8212; randomly shaped asteroids for a more unique experience.
<span id="more-8"></span>
The other is that I&#8217;ve gone back to the Drawing API for the asteroids, so the Asteroids are now (almost) entirely ActionScript.  I&#8217;ll move the ship back under its controls in a future release.  In fact, getting this to work the way I did reveals that I&#8217;ll have to set up a &#8220;Game&#8221; class to generate the movieclips that will bind to the Asteroid and the Ship classes &#8212; and in that class, not only should I be able to move out of having any movieclips in the library &#8212; I should be able to incorporate the collision detection between the asteroids and the ship.</p>

<p>I think I&#8217;m getting classes now.  Here&#8217;s the updated code for the Asteroid class&#8230;</p>

<p><code></p>

<pre>
class Asteroid extends MovieClip
{
    // velocity value for the Asteroid's x- and y- movement
    private var xv:Number;
    private var yv:Number;

    // rotation of the Asteroid, so it looks like it drifts
    // in outer space
    private var r:Number;

    private var AsteroidColor:Number = 0x00CC00;

    // this is the constructor function, which initializes
    // each Asteroid instance.  It must be a public function
    // or it won't be able to be accessed by the Flash movie.
    private function Asteroid ()
    {
        DrawAsteroid( this );

        // shorten up some Math functions
        var mr = Math.random;
        var mf = Math.floor;

        // set the velocity for the Asteroid
        xv = mf( mr() * 6 ) - 3;
        yv = mf( mr() * 6 ) - 3;

        // set the Asteroid's original rotation.
        r = mf( mr() * 360 ) - 180;
        _rotation = r;

    }

    // Each Asteroid will now encapsulates, or
    // determintes its own movement.  This will
    // improve performance over the original
    // game, where one onEnterFrame on the _root
    // controlled everything.
    private function onEnterFrame():Void
    {
        // This series of if statements simply guides the placement
        // of an asteroid as it floats near the borders of the movie.
        if ( _x < = 10 ) 
        {
            _x += 390;
        }
        if ( _x >= 390 ) 
        {
            _x -= 390;
        }
        if ( _y < = 10 ) 
        {
            _y += 140;
        }
        if ( _y >= 140 ) 
        {
            _y -= 140;
        }

        // Keep the Asteroid moving per its velocity
        _x += xv;
        _y += yv;

        // Keep the Asteroid rotating on its axis, as if it were floating
        // in space.
        _rotation += r / 60;
    }

    private function DrawRectangle ( shape )
    {
        shape.beginFill ( AsteroidColor, 100 );
        shape.lineTo ( 30, 0 );
        shape.lineTo ( 30, -30 );
        shape.lineTo ( 0, -30 );
        shape.lineTo ( 0, 0 );
    }

    // DrawRectangle();

    private function DrawTriangle ( shape )
    {
        shape.beginFill ( AsteroidColor, 100 );
        shape.lineTo ( 30, 0 );
        shape.lineTo ( 0, -30 );
        shape.lineTo ( 0, 0 );
    }


    private function DrawAsteroid( mc )
    {
        var degrees:Number = 360;

        while ( degrees -= 45 )
        {
            var i:Number = Math.floor( Math.random() * 2);
            var shape:MovieClip = this.createEmptyMovieClip( "shape" + degrees, this.getNextHighestDepth() );
            (i) ?  DrawRectangle( shape ) : DrawTriangle( shape );
            shape._rotation = degrees;
        }
    }   
}
</pre>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/asteroids-203-new-asteroid-shapes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Asteroids 2.02: Ship It!</title>
		<link>http://flashforlearning.com/2005/04/asteroids-202-ship-it/</link>
		<comments>http://flashforlearning.com/2005/04/asteroids-202-ship-it/#comments</comments>
		<pubDate>Fri, 15 Apr 2005 21:23:58 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[Animation]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=7</guid>
		<description><![CDATA[<p>It would figure that success breeds more success, and now I have a ship that flys about the screen using the arrow keys, again controlled via a Ship class.  Try it for yourself right here!</p>
]]></description>
			<content:encoded><![CDATA[<p>It would figure that success breeds more success, and now I have a ship that flys about the screen using the arrow keys, again controlled via a Ship class.  Try it for yourself right here!</p>

<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="150">
  <param name="movie" value="http://flashforlearning.com/files/Asteroids_02.swf">
  </param><param name=quality value=high>
  <embed src="http://flashforlearning.com/files/Asteroids_02.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="150"></embed>
</param></object></p>

<p><a href="http://flashforlearning.com/files/Asteroids_02.zip">Download the source files</a>.
<span id="more-7"></span>
Again, much like the <a href="http://www.macromedia.com/devnet/mx/flash/articles/asteroids05.html">original source</a>, the class structure as presented below looks similar.  Since the asteroids move about with their own behaviors, and those behaviors are really separate from the ship&#8217;s behaviors, it&#8217;s easy to do this really clean.</p>

<p>I&#8217;m very curious about how these items will interact, and more pertinent to me, what that resulting code will be like.</p>

<p>In the meantime, if you&#8217;re playing along at your own computer, create a Ship movieclip and bind it to a Ship.as class file, which looks like this:</p>

<pre>
<code>
class Ship extends MovieClip
{
    public var torque:Number;
    public var rtorque:Number;
    public var AngVelocity:Number;
    public var AngAcceleration:Number;
    // angle is the ship's rotation angle.
    public var angle:Number;

    public var force:Number;

    // xv is the ship's x-velocity (going across)
    public var xv:Number;

    // yv is the ship's y-velocity (going up/down)
    public var yv:Number;

    // x is the ship's x-position.
    public var x:Number;

    // y is the ship's y-position.
    public var y:Number;

    // xa is the ship's x-acceleration (how it speeds up/slows down)
    public var xa:Number;

    // ya is the ship's y-acceleration (how it speeds up/slows down)
    public var ya:Number;

    // v is the ship's "vector"
    public var v:Number;

    // the ship has a "momentum" factor to slow down some response time.
    public var momentum:Number;

    // drag will use the momentum factor
    public var drag:Number;

    // We're going to put a timer in for the firing engine, so we don't fire all our
    // lasers at the same time - spacing out the firing to make better shooting.
    public var timer:Number;

    // We'll set up an array of object references to each laser.
    //public var lasers:Array;


    private function Ship()
    {
        angle = 0;  
        xv = 0;         
        x = 0;      
        y = 0;      
        yv = 0;         
        xa = 0;         
        ya = 0;         
        v = 0;      
        momentum = 0.02;    
        drag = 0;
        timer = 0;
        AngVelocity = 0;
        AngAcceleration = 0;
    }

    public function onEnterFrame()
    {
        // RIGHT and LEFT control the amount of torque applied to the ship's movement
        if ( Key.isDown( Key.RIGHT ) )
        {
            torque = 5;
        } 
        else if ( Key.isDown( Key.LEFT ) )
        {
            torque = -5;
        } 
        else 
        {
            torque = 0;
        }

        rtorque = 0.5 * AngVelocity;
        AngAcceleration = torque - rtorque;
        AngVelocity += AngAcceleration;
        angle += AngVelocity;

        // constrain theta 0 < 360
        // We only want to deal with angles from 0 to 360 degrees
        if ( angle < 0 ) 
        {
            angle += 360;
        }
        if ( angle > 360 ) 
        {
            angle -= 360;
        }


        v = Math.sqrt( Math.pow( xv, 2) + Math.pow( yv, 2) );

        drag = momentum * v;

        // Here we control the thrust and acceleration of the ship
        force = ( Key.isDown( Key.UP ) ) ? 1 : 0;

        xa = ( ( drag * xv ) * -1 ) + ( force * Math.sin( Math.PI / 180 * angle ) );
        ya = ( ( drag * yv ) * -1 ) - ( force * Math.cos( Math.PI / 180 * angle ) );
        xv += xa;
        yv += ya;

        // Just like the Asteroids, we need to constrain the ship within
        // the bounds of the playable area.
        if ( _x < = 10 ) 
        {
            _x += 390;
        }
        if ( _x >= 390 ) 
        {
            _x -= 390;
        }
        if ( _y < = 10 ) 
        {
            _y += 140;
        }
        if ( _y >= 140 ) 
        {
            _y -= 140;
        }
        // And here we finally assign and update the ship's x- and
        // y- positions, and its rotation angle.
        _y += yv;
        _x += xv;
        _rotation = angle;
        // ... END movement
    }
}
</code> 
</pre>

<p>Commments?  Suggestions?  Bugs?</p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/asteroids-202-ship-it/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Asteroids 2.01: Making the Asteroids Move</title>
		<link>http://flashforlearning.com/2005/04/asteroids-201-making-the-asteroids-move/</link>
		<comments>http://flashforlearning.com/2005/04/asteroids-201-making-the-asteroids-move/#comments</comments>
		<pubDate>Fri, 15 Apr 2005 11:30:00 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[Animation]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=6</guid>
		<description><![CDATA[<p>With a taste of success under my belt, I started remaking the Asteroids game using ActionSctipt 2.0 and class structure.</p>
]]></description>
			<content:encoded><![CDATA[<p>With a taste of success under my belt, I started remaking the Asteroids game using ActionSctipt 2.0 and class structure.</p>

<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="150">
  <param name="movie" value="http://flashforlearning.com/files/Asteroids_01.swf">
  </param><param name=quality value=high>
  <embed src="http://flashforlearning.com/files/Asteroids_01.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="150"></embed>
</param></object></p>

<p><a href="http://flashforlearning.com/files/Asteroids_01.zip">Download the source files</a>.</p>

<p>While the Asteroids you see here are movieclips with polygon fills, unlike the completely code-rendered Asteroids in the original game, there is no code in the entire flash movie.  All the code takes place in the Asteroid.as class file that each Asteroid movieclip is bound to.  I didn&#8217;t even have to instantiate these Asteroids for them to behave.  I just drag them out of the library and let them do their thing.
<span id="more-6"></span>
Notice any similarities between the <a href="http://flashforlearning.com/archives/2005/04/linear_sprites.php">LinearSprite code</a> and the following code?  <a href="http://www.macromedia.com/devnet/mx/flash/articles/asteroids03.html">It&#8217;s a natural progression from the original code</a>.  We&#8217;ll see in later entries if this has to change&#8230;</p>

<p><code></p>

<pre>
class Asteroid extends MovieClip
{
    // velocity value for the Asteroid's x- and y- movement
    private var xv:Number;
    private var yv:Number;

    // rotation of the Asteroid, so it looks like it drifts
    // in outer space
    private var r:Number;

    // this is the constructor function, which initializes
    // each Asteroid instance.  It must be a public function
    // or it won't be able to be accessed by the Flash movie.
    private function Asteroid ()
    {
        // shorten up some Math functions
        var mr = Math.random;
        var mf = Math.floor;

        // set the velocity for the Asteroid
        xv = mf( mr() * 6 ) - 3;
        yv = mf( mr() * 6 ) - 3;

        // set the Asteroid's original rotation.
        r = mf( mr() * 360 ) - 180;
        _rotation = r;

    }

    // Each Asteroid will now encapsulates, or
    // determintes its own movement.  This will
    // improve performance over the original
    // game, where one onEnterFrame on the _root
    // controlled everything.
    private function onEnterFrame():Void
    {
        // This series of if statements simply guides the placement
        // of an asteroid as it floats near the borders of the movie.
        if ( _x < = 10 ) 
        {
            _x += 390;
        }
        if ( _x >= 390 ) 
        {
            _x -= 390;
        }
        if ( _y < = 10 ) 
        {
            _y += 140;
        }
        if ( _y >= 140 ) 
        {
            _y -= 140;
        }

        // Keep the Asteroid moving per its velocity
        _x += xv;
        _y += yv;

        // Keep the Asteroid rotating on its axis, as if it were floating
        // in space.
        _rotation += r / 60;
    }
}
</pre>

<p></code></p>

<p>Please use the comments feature here to ask any questions, or make any suggestions to improving the code.  I want to build the best asteroids game I can with ActionScript 2.0&#8230; and I&#8217;m more than willing to incorporate your ideas!</p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/asteroids-201-making-the-asteroids-move/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linear Sprites</title>
		<link>http://flashforlearning.com/2005/04/linear-sprites/</link>
		<comments>http://flashforlearning.com/2005/04/linear-sprites/#comments</comments>
		<pubDate>Thu, 14 Apr 2005 03:21:45 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
		
		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[Animation]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://beta.aaron21.com/?p=5</guid>
		<description><![CDATA[<p>Directly associating Classes to movieclips isn't the only approach you can use in grasping OOP with ActionScript 2.0, but it's a great start for understanding how theoretical object structures can relate to the virtual objects that you can manipulate in Flash's IDE.</p>
]]></description>
			<content:encoded><![CDATA[<p>Starting from scratch at understanding just how Object-Oriented Programming, ActionScript 2.0 models inside of Flash.  I took a stab at what <a href="http://www.gskinner.com/blog/archives/2005/04/object_oriented.html">Grant Skinner</a> spoke about at FlashForward 2005 in San Francisco (last week).  Here&#8217;s the finished product&#8230;</p>

<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="150">
  <param name="movie" value="http://flashforlearning.com/files/LinearSprite.swf">
  </param><param name=quality value=high>
  <embed src="http://flashforlearning.com/files/LinearSprite.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="400" height="150"></embed>
</param></object></p>

<p><a href="http://flashforlearning.com/files/LinearSprite.zip">Download the source files</a>.</p>

<p>Grant&#8217;s a pretty smart guy.  Sure the example he wrote above isn&#8217;t terribly sexy, but Grant revealed a key element in how to conceive of OOP in a way that bridges most developers&#8217; understanding of Flash and very evident objects &#8212; associating movieclip behaviors with a class that describes the behavior.</p>

<p>I&#8217;m going to journal these experiments, working my way up to rebuilding my (somewhat famous) Asteroids code with ActionScript 2.0.</p>

<p>But for now, let&#8217;s get back to the basics&#8230;</p>

<p>Directly associating Classes to movieclips isn&#8217;t the only approach you can use in grasping OOP with ActionScript 2.0, but it&#8217;s a great start for understanding how theoretical object structures can relate to the virtual objects that you can manipulate in Flash&#8217;s IDE.
<span id="more-5"></span>
All I did in this example was to create a movieclip, just as Grant described in his presentation, and link it with a class file of the same name as the linkage for that movieclip out of the library.</p>

<p>The code for the class is here, and as you might guess, it&#8217;s saved as an ActionScript file (&#8221;LinearSprite.as&#8221;):</p>

<pre>
<code>
class LinearSprite extends MovieClip
{
    private var xvel:Number;
    private var yvel:Number;

    private function LinearSprite()
    {
        xvel = 2 + random( 80 ) / 10;
        yvel = 2 + random( 80 ) / 10;
    }

    private function onEnterFrame():Void
    {
        _x += xvel;
        _y += yvel;

        if ( ( _x > 400 &#038;&#038; xvel > 0 ) || ( _x < 0 &#038;&#038; xvel < 0 ) ) { xvel *= -1; }
        if ( ( _y > 150 &#038;&#038; yvel > 0 ) || ( _y < 0 &#038;&#038; yvel < 0 ) ) { yvel *= -1; }
    }
}
</code>
</code></pre>

<p>So basically, in my Flash example above, I dragged four of these sprites onto the stage, and they&#8217;re just doing what they do.  It certainly runs pretty smooth with each sprite responsible for its own movement, rather than the timeline chugging through the <code>onEnterFrame</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://flashforlearning.com/2005/04/linear-sprites/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
