<?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>Chasing &#187; actionscript</title>
	<atom:link href="http://chase.ratchetsoftware.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://chase.ratchetsoftware.com</link>
	<description>Chase Gray&#039;s blog with solutions to various problems by a curious american Ph.D. student.</description>
	<lastBuildDate>Wed, 09 Jun 2010 05:13:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Necklace Simulation</title>
		<link>http://chase.ratchetsoftware.com/2008/09/necklace-simulation/</link>
		<comments>http://chase.ratchetsoftware.com/2008/09/necklace-simulation/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 19:51:28 +0000</pubDate>
		<dc:creator>chasemgray</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://chase.ratchetsoftware.com/?p=54</guid>
		<description><![CDATA[I had some ideas that required some sort of necklace simulator through a web interface.  I didn&#8217;t have much experience programming anything complex in ActionScript, but I was sure that would be the way to go.  I have seen some amazing work done with Flash applications over the past few years and I had no [...]]]></description>
			<content:encoded><![CDATA[<p>I had some ideas that required some sort of necklace simulator through a web interface.  I didn&#8217;t have much experience programming anything complex in ActionScript, but I was sure that would be the way to go.  I have seen some amazing work done with Flash applications over the past few years and I had no doubt that Flash could handle such an application.  So I set out on one weekend to put together a quick prototype for my idea.</p>
<p><span id="more-54"></span></p>
<p>Of course the first question I had was what physics libraries are available for Flash these days.  I had some experience in the past using Newton and various wrappers in C++ for a game project.  My experience with Newton would end up helping me pick up a new physics engine relatively easy.</p>
<p>There were a couple of choices to choose from and I started my search by reading some reviews found on <a title="Geek Glue Actionscript Physics Engine Overview" href="http://http://geekglue.blogspot.com/2008/01/actionscript-2d-physics-engines.html" target="_blank">GeekGlue.</a> From this I was able to reduce my search to the <a title="APE" href="http://www.cove.org/ape/index.htm" target="_blank">Actionscript Physics Engine (APE)</a> and<a title="Box2D Flash ActionScript 3" href="http://box2dflash.sourceforge.net/" target="_blank"> Box2DFlashAS3</a>.  APE seemed much easier to get started with, but I wasn&#8217;t sure if it would accomplish what I wanted without a lot of massaging.  After further reading on some forums, I found that the rope simulation in APE is much more limited because there is only one type of joint available at this time.  Box2D has 6 different types of joints and their provided rope bridge looked a little better.  The fact that Box2D had ragdoll physics examples made me feel that I would have as much control as I needed to create the necklace simulation I wanted.</p>
<p>After choosing Box2D I wanted to take their rope &#8220;springy&#8221; bridge demo and see if that could be easily turned into some sort of free falling rope.  This was not as simple as adding links and changing a few variables like I had hoped.  If you simply add links to the rope, after adding too many the iterative solver breaks the joints with the default configuration.  I had to search for a while to figure out why this was.  After some searching, I found that a joint can only handle about a 10:1 weight ratio before giving out.  The solution to this is the increase the number of iterations of decrease the step time.  This of course will slow down your simulation depending on how much you have to increase the number of iterations.  I had to change mine from about 10 to 40.  My simulation was still running at a decent speed but in the future I am not sure how this will hold up with more physics bodies flying around.  This was a huge problem for a while for me and I was very glad to finally find a solution.  If you have joints that are breaking due to too much force being applied to them is too much without adding more iterations to the engine so it can accurately solve the joint forces.  I hope someone with a similar problem can find this post because it took me a while to find a solution on a forum somewhere.</p>
<p>I am not concerned with creating a nice looking application at this time since this was just a weekend project I was doing on the side.  The goals for the prototype of my necklace simulator I wanted to have  the following:</p>
<ol>
<li>A rope like necklace that could be moved around by the user with realistic physics.</li>
<li>Two end pieces on the necklace that were different than the rest of the necklace and could be connected to things.</li>
<li>Two or more connectors in the world that could have a necklace endpiece connected to them and unattached when the user wants to move the necklace again.</li>
<li>A prototype of a bead which can be moved by the user and placed on the necklace.</li>
<li>A background of a neck or something so that it is easy to see what the necklace would look like on a person.</li>
</ol>
<p>For my resulting application, I simply modified the default Test class provided with Box2DFlashAS3 to have instances of the objects in the world such as the rope and beads.  Previously it was a base class for various tests.  This might not be the best solution, but it was fine for my prototype to see if things would work.  I&#8217;ll include the entire source here and highlight my changes as well.</p>
<p><strong>Playground.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">package</span> TestBed<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Contacts.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Main;
	<span style="color: #0033ff; font-weight: bold;">import</span> General.Input;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #004993;">getTimer</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Playground<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Playground<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
			m_sprite = Main.m_sprite;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> worldAABB<span style="color: #000000; font-weight: bold;">:</span>b2AABB = <span style="color: #0033ff; font-weight: bold;">new</span> b2AABB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			worldAABB.lowerBound.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1000.0</span>, <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1000.0</span><span style="color: #000000;">&#41;</span>;
			worldAABB.upperBound.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000.0</span>, <span style="color: #000000; font-weight:bold;">1000.0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Define the gravity vector</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> gravity<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.0</span>, <span style="color: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Allow bodies to sleep</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> doSleep<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
			<span style="color: #009900;">// Construct a world object</span>
			m_world = <span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span>worldAABB, gravity, doSleep<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// set debug draw</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> dbgDraw<span style="color: #000000; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//var dbgSprite:Sprite = new Sprite();</span>
			<span style="color: #009900;">//m_sprite.addChild(dbgSprite);</span>
			dbgDraw.m_sprite = m_sprite;
			dbgDraw.m_drawScale = <span style="color: #000000; font-weight:bold;">30.0</span>;
			dbgDraw.m_fillAlpha = <span style="color: #000000; font-weight:bold;">0.3</span>;
			dbgDraw.m_lineThickness = <span style="color: #000000; font-weight:bold;">1.0</span>;
			dbgDraw.m_drawFlags = b2DebugDraw.e_shapeBit <span style="color: #000000; font-weight: bold;">|</span> b2DebugDraw.e_jointBit;
			m_world.SetDebugDraw<span style="color: #000000;">&#40;</span>dbgDraw<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Create border of boxes</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wallSd<span style="color: #000000; font-weight: bold;">:</span>b2PolygonDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> wallBd<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> wallB<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
			<span style="color: #009900;">// Left</span>
			wallBd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">95</span> <span style="color: #000000; font-weight: bold;">/</span> m_physScale, <span style="color: #000000; font-weight:bold;">360</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
			wallSd.SetAsBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale, <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
			wallB = m_world.CreateBody<span style="color: #000000;">&#40;</span>wallBd<span style="color: #000000;">&#41;</span>;
			wallB.CreateShape<span style="color: #000000;">&#40;</span>wallSd<span style="color: #000000;">&#41;</span>;
			wallB.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// Right</span>
			wallBd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">640</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">95</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> m_physScale, <span style="color: #000000; font-weight:bold;">360</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
			wallB = m_world.CreateBody<span style="color: #000000;">&#40;</span>wallBd<span style="color: #000000;">&#41;</span>;
			wallB.CreateShape<span style="color: #000000;">&#40;</span>wallSd<span style="color: #000000;">&#41;</span>;
			wallB.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// Top</span>
			wallBd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">640</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">95</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
			wallSd.SetAsBox<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">680</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//wallB = m_world.CreateBody(wallBd);</span>
			<span style="color: #009900;">//wallB.CreateShape(wallSd);</span>
			<span style="color: #009900;">//wallB.SetMassFromShapes();</span>
			<span style="color: #009900;">// Bottom</span>
			wallBd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">640</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">360</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">95</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
			wallB = m_world.CreateBody<span style="color: #000000;">&#40;</span>wallBd<span style="color: #000000;">&#41;</span>;
			wallB.CreateShape<span style="color: #000000;">&#40;</span>wallSd<span style="color: #000000;">&#41;</span>;
			wallB.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			m_rope = <span style="color: #0033ff; font-weight: bold;">new</span> Rope<span style="color: #000000;">&#40;</span>m_world, m_physScale<span style="color: #000000;">&#41;</span>;
&nbsp;
			m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
			m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
&nbsp;
			m_leftHook = <span style="color: #0033ff; font-weight: bold;">new</span> Hook<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">175</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale, <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
			m_rightHook = <span style="color: #0033ff; font-weight: bold;">new</span> Hook<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale, <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
			m_hookJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			m_bead = <span style="color: #0033ff; font-weight: bold;">new</span> Bead<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #000000; font-weight:bold;">7.5</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #009900;">// Update mouse joint</span>
			UpdateMouseWorld<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
			MouseDestroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			MouseDrag<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Update physics</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> physStart<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			m_world.Step<span style="color: #000000;">&#40;</span>m_timeStep, m_iterations<span style="color: #000000;">&#41;</span>;
			Main.m_fpsCounter.updatePhys<span style="color: #000000;">&#40;</span>physStart<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">//======================</span>
		<span style="color: #009900;">// Member Data</span>
		<span style="color: #009900;">//======================</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_world<span style="color: #000000; font-weight: bold;">:</span>b2World;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_mouseJoint<span style="color: #000000; font-weight: bold;">:</span>b2MouseJoint;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_iterations<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">40</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_timeStep<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_physScale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">30</span>;
		<span style="color: #009900;">// world mouse position</span>
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> mouseXWorldPhys<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> mouseYWorldPhys<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> mouseXWorld<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> mouseYWorld<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
		<span style="color: #009900;">// Sprite to draw in to</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rope<span style="color: #000000; font-weight: bold;">:</span>Rope;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_hookJointDef<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_leftHookJoint<span style="color: #000000; font-weight: bold;">:</span>b2Joint;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rightHookJoint<span style="color: #000000; font-weight: bold;">:</span>b2Joint;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_leftHook<span style="color: #000000; font-weight: bold;">:</span>Hook;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rightHook<span style="color: #000000; font-weight: bold;">:</span>Hook;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_bead<span style="color: #000000; font-weight: bold;">:</span>Bead;
&nbsp;
		<span style="color: #009900;">//======================</span>
		<span style="color: #009900;">// Update mouseWorld</span>
		<span style="color: #009900;">//======================</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> UpdateMouseWorld<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
			mouseXWorldPhys = <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseX</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale;
			mouseYWorldPhys = <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale; 
&nbsp;
			mouseXWorld = <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseX</span><span style="color: #000000;">&#41;</span>;
			mouseYWorld = <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">//======================</span>
		<span style="color: #009900;">// Mouse Drag</span>
		<span style="color: #009900;">//======================</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MouseDrag<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// mouse press</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseDown</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #000000; font-weight: bold;">!</span>m_mouseJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body = GetBodyAtMouse<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> md<span style="color: #000000; font-weight: bold;">:</span>b2MouseJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2MouseJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					md.body1 = m_world.GetGroundBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					md.body2 = body;
					md.<span style="color: #004993;">target</span>.Set<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span>;
					md.maxForce = <span style="color: #000000; font-weight:bold;">600.0</span> <span style="color: #000000; font-weight: bold;">*</span> body.GetMass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					md.timeStep = m_timeStep;
					m_mouseJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>md<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2MouseJoint;
					body.WakeUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body == m_rope.m_leftHook <span style="color: #000000; font-weight: bold;">||</span> body == m_rope.m_rightHook<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHookJoint <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; body == m_leftHookJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
								m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span>;
								m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHookJoint <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; body == m_rightHookJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
								m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span>;
								m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body == m_bead.m_body<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						m_bead.SetCollidable<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #009900;">// mouse release</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>Input.<span style="color: #004993;">mouseDown</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #009900;">//get body being clicked on</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> clickedBody<span style="color: #000000; font-weight: bold;">:</span>b2Body = m_mouseJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>;
					m_mouseJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>clickedBody == m_bead.m_body<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						m_bead.SetCollidable<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rope.IsAttachable<span style="color: #000000;">&#40;</span> clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
&nbsp;
						<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2Body = m_world.GetGroundBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHook.IsTouching<span style="color: #000000;">&#40;</span>clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;test&quot;</span><span style="color: #000000;">&#41;</span>;
							m_hookJointDef.Initialize<span style="color: #000000;">&#40;</span>m_leftHook.m_body,  clickedBody, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
								m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span>;
								m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
							<span style="color: #000000;">&#125;</span>
							m_leftHookJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>m_hookJointDef<span style="color: #000000;">&#41;</span>;
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHook.IsTouching<span style="color: #000000;">&#40;</span> clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
								m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span>;
								m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
							<span style="color: #000000;">&#125;</span>
							m_hookJointDef.Initialize<span style="color: #000000;">&#40;</span>m_rightHook.m_body,  clickedBody,  <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
							m_rightHookJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>m_hookJointDef<span style="color: #000000;">&#41;</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #009900;">// mouse move</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span>;
				m_mouseJoint.SetTarget<span style="color: #000000;">&#40;</span>p2<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">//======================</span>
		<span style="color: #009900;">// Mouse Destroy</span>
		<span style="color: #009900;">//======================</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MouseDestroy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// mouse press</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>Input.<span style="color: #004993;">mouseDown</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; Input.isKeyPressed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">68</span><span style="color: #3f5fbf;">/*D*/</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body = GetBodyAtMouse<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					m_world.DestroyBody<span style="color: #000000;">&#40;</span>body<span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">return</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">//======================</span>
		<span style="color: #009900;">// GetBodyAtMouse</span>
		<span style="color: #009900;">//======================</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mousePVec<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> GetBodyAtMouse<span style="color: #000000;">&#40;</span>includeStatic<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>b2Body<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// Make a small box.</span>
			mousePVec.Set<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> aabb<span style="color: #000000; font-weight: bold;">:</span>b2AABB = <span style="color: #0033ff; font-weight: bold;">new</span> b2AABB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			aabb.lowerBound.Set<span style="color: #000000;">&#40;</span>mouseXWorldPhys <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">0.001</span>, mouseYWorldPhys <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">0.001</span><span style="color: #000000;">&#41;</span>;
			aabb.upperBound.Set<span style="color: #000000;">&#40;</span>mouseXWorldPhys <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.001</span>, mouseYWorldPhys <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.001</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Query the world for overlapping shapes.</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> k_maxCount<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> shapes<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> count<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = m_world.Query<span style="color: #000000;">&#40;</span>aabb, shapes, k_maxCount<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body = <span style="color: #0033ff; font-weight: bold;">null</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&amp;</span>lt; count; <span style="color: #000000; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>shapes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.IsStatic<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == <span style="color: #0033ff; font-weight: bold;">false</span> <span style="color: #000000; font-weight: bold;">||</span> includeStatic<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> tShape<span style="color: #000000; font-weight: bold;">:</span>b2Shape = shapes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2Shape;
					<span style="color: #6699cc; font-weight: bold;">var</span> inside<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = tShape.TestPoint<span style="color: #000000;">&#40;</span>tShape.GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.GetXForm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, mousePVec<span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>inside<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						body = tShape.GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> body;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The first change is at the end of the constructor where I create the items that are in the world.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">m_rope = <span style="color: #0033ff; font-weight: bold;">new</span> Rope<span style="color: #000000;">&#40;</span>m_world, m_physScale<span style="color: #000000;">&#41;</span>;
&nbsp;
m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
&nbsp;
m_leftHook = <span style="color: #0033ff; font-weight: bold;">new</span> Hook<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">175</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale, <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
m_rightHook = <span style="color: #0033ff; font-weight: bold;">new</span> Hook<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale, <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;
m_hookJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
m_bead = <span style="color: #0033ff; font-weight: bold;">new</span> Bead<span style="color: #000000;">&#40;</span>m_world, m_physScale, <span style="color: #000000; font-weight:bold;">7.5</span><span style="color: #000000; font-weight: bold;">/</span>m_physScale<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>The second noticable difference is the addition of the member variables.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rope<span style="color: #000000; font-weight: bold;">:</span>Rope;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_hookJointDef<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_leftHookJoint<span style="color: #000000; font-weight: bold;">:</span>b2Joint;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rightHookJoint<span style="color: #000000; font-weight: bold;">:</span>b2Joint;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_leftHook<span style="color: #000000; font-weight: bold;">:</span>Hook;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rightHook<span style="color: #000000; font-weight: bold;">:</span>Hook;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_bead<span style="color: #000000; font-weight: bold;">:</span>Bead;</pre></div></div>

<p>In the mouse drag function are the most important additions.  In the first part of this function we are focusing on mouse presses, or an initiated drag.  The first thing we do is check to see if we clicked on a joint at one of our hooking points, if so we want to destroy that joint and let the mouse move the necklace wherever it wants to.  We also want the user to be able to click a bead and place it on the necklace without colliding with the necklace while trying to drag the bead, this is also check for here, we turn off collisions for a bead if it is being dragged.</p>
<p>\The second part of the mouse drag function is when the mouse button is relased after dragging has occurred.  When this happens, we check to see if we were holding a bead, if we were we set it to be collidable, so that it will stay on the necklace if it was placed there.  We are also checking to see if the right or left hook are clicked on with one of the end pieces of the necklace.  If they are then we create a new joint between the hook and the necklace endpiece.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//======================</span>
<span style="color: #009900;">//======================</span>
<span style="color: #009900;">// Mouse Drag</span>
<span style="color: #009900;">//======================</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MouseDrag<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
	<span style="color: #009900;">// mouse press</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Input.<span style="color: #004993;">mouseDown</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #000000; font-weight: bold;">!</span>m_mouseJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body = GetBodyAtMouse<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> md<span style="color: #000000; font-weight: bold;">:</span>b2MouseJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2MouseJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			md.body1 = m_world.GetGroundBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			md.body2 = body;
			md.<span style="color: #004993;">target</span>.Set<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span>;
			md.maxForce = <span style="color: #000000; font-weight:bold;">600.0</span> <span style="color: #000000; font-weight: bold;">*</span> body.GetMass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			md.timeStep = m_timeStep;
			m_mouseJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>md<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2MouseJoint;
			body.WakeUp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body == m_rope.m_leftHook <span style="color: #000000; font-weight: bold;">||</span> body == m_rope.m_rightHook<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHookJoint <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; body == m_leftHookJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
						m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span>;
						m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHookJoint <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; body == m_rightHookJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
						m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span>;
						m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body == m_bead.m_body<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				m_bead.SetCollidable<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// mouse release</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>Input.<span style="color: #004993;">mouseDown</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//get body being clicked on</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> clickedBody<span style="color: #000000; font-weight: bold;">:</span>b2Body = m_mouseJoint.GetBody2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>;
			m_mouseJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>clickedBody == m_bead.m_body<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				m_bead.SetCollidable<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rope.IsAttachable<span style="color: #000000;">&#40;</span> clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2Body = m_world.GetGroundBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHook.IsTouching<span style="color: #000000;">&#40;</span>clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;test&quot;</span><span style="color: #000000;">&#41;</span>;
					m_hookJointDef.Initialize<span style="color: #000000;">&#40;</span>m_leftHook.m_body,  clickedBody, <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
						m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_leftHookJoint<span style="color: #000000;">&#41;</span>;
						m_leftHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
					<span style="color: #000000;">&#125;</span>
					m_leftHookJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>m_hookJointDef<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHook.IsTouching<span style="color: #000000;">&#40;</span> clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
						m_world.DestroyJoint<span style="color: #000000;">&#40;</span>m_rightHookJoint<span style="color: #000000;">&#41;</span>;
						m_rightHookJoint = <span style="color: #0033ff; font-weight: bold;">null</span>;
					<span style="color: #000000;">&#125;</span>
					m_hookJointDef.Initialize<span style="color: #000000;">&#40;</span>m_rightHook.m_body,  clickedBody,  <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
					m_rightHookJoint = m_world.CreateJoint<span style="color: #000000;">&#40;</span>m_hookJointDef<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// mouse move</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>m_mouseJoint<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>mouseXWorldPhys, mouseYWorldPhys<span style="color: #000000;">&#41;</span>;
		m_mouseJoint.SetTarget<span style="color: #000000;">&#40;</span>p2<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>There are three types that are used in the Playground.as file that we haven&#8217;t seen and are not in Box2D.  Those are the Rope, Bead, and Hook classes.</p>
<p>The rope is the most complicated and has the most new code.  When instantiated it builds itself vertically at a hard coded location.  It has an endpiece on each end that is different than the rest of the necklace.   Initially I made all pieces of the necklace a rectangle and connected them end to end.  This proved to be a mistake because when there was too much bending or twisting between two rectangle shapes at a joint they would sometimes not know how to fix themselves.  It would look like a permanent crease between the joint.  I was unable to figure out how to fix this problem with rectangles and I figured collisions between spheres is always cheaper so I moved everything to circles.</p>
<p>So the result is that the rope is made up of anywhere between 10 and 60 circles.  The values for the number of circles and the size of them is currently hard coded in the rope.as file.  Most of what is happening during the building of the rope is pretty obvious.  I changed a couple of the collision properties to make things look more realistic.</p>
<p>Each end piece is special and can be attached to a connector in the stage.  The isAttachable function checks to see if a given body can be attached to something.  I did this so it was easy to change which things could be attached in the future.</p>
<p>One last thing to note is that I made the end pieces collidable with the necklace pieces but the necklace pieces are not collidable with themselves.  This saves a lot of computation I&#8217;m sure but the main reason was so that you could more easily find an endpiece among a pile of necklace since it should be sitting on top.</p>
<p><strong>Rope.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Contacts.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Rope<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Rope<span style="color: #000000;">&#40;</span>world<span style="color: #000000; font-weight: bold;">:</span>b2World, physScale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #009900;">// Set block length &amp;amp; width &amp;amp; overlap(to make block connections look smoother)</span>
		m_blockLength =<span style="color: #000000; font-weight:bold;">3.5</span>;
		m_blockWidth = <span style="color: #000000; font-weight:bold;">3.5</span>;
		m_overlap = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">4.5</span>;
		<span style="color: #009900;">// Set end piece paramaters</span>
		m_circleRadius = <span style="color: #000000; font-weight:bold;">3</span>;
&nbsp;
		<span style="color: #009900;">// Starting height for necklace</span>
		m_startingHeight = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span>; 
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> vel<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		vel.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span>, <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>; 
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000000; font-weight: bold;">:</span>b2Body = world.GetGroundBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> anchor<span style="color: #000000; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
		<span style="color: #009900;">// Bridge</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> sd<span style="color: #000000; font-weight: bold;">:</span>b2PolygonDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			sd.SetAsBox<span style="color: #000000;">&#40;</span>m_blockLength <span style="color: #000000; font-weight: bold;">/</span> physScale, m_blockWidth <span style="color: #000000; font-weight: bold;">/</span> physScale<span style="color: #000000;">&#41;</span>;
			sd.density = <span style="color: #000000; font-weight:bold;">20</span>;
			sd.friction = .8;
			sd.restitution = <span style="color: #000000; font-weight:bold;">0.0</span>;
			sd.<span style="color: #004993;">filter</span>.groupIndex = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> cd<span style="color: #000000; font-weight: bold;">:</span>b2CircleDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cd.density = <span style="color: #000000; font-weight:bold;">20.0</span>;
			cd.radius = <span style="color: #000000;">&#40;</span>m_circleRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> physScale;
			cd.restitution = <span style="color: #000000; font-weight:bold;">0.0</span>;
			cd.friction=<span style="color: #000000; font-weight:bold;">0.8</span>;
			cd.<span style="color: #004993;">filter</span>.groupIndex = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">3</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> bd<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			bd.<span style="color: #004993;">angle</span> = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> jd<span style="color: #000000; font-weight: bold;">:</span>b2RevoluteJointDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2RevoluteJointDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			const numPlanks<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">50</span>;
&nbsp;
			jd.lowerAngle = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span>;
			jd.upperAngle = <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span>;
			jd.enableLimit = <span style="color: #0033ff; font-weight: bold;">false</span>;
			jd.collideConnected = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> prevBody<span style="color: #000000; font-weight: bold;">:</span>b2Body = ground;
&nbsp;
			bd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span> <span style="color: #000000; font-weight: bold;">/</span> physScale, <span style="color: #000000;">&#40;</span>m_startingHeight <span style="color: #000000; font-weight: bold;">+</span> m_blockLength<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>physScale<span style="color: #000000;">&#41;</span>
			<span style="color: #009900;">//bd.isBullet = true;</span>
			body = world.CreateBody<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span>;
			body.CreateShape<span style="color: #000000;">&#40;</span>sd<span style="color: #000000;">&#41;</span>;
			body.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			body.SetLinearVelocity<span style="color: #000000;">&#40;</span>vel<span style="color: #000000;">&#41;</span>;
			m_leftHook = prevBody = body;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&amp;</span>lt; numPlanks; <span style="color: #000000; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				bd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span> <span style="color: #000000; font-weight: bold;">/</span> physScale, <span style="color: #000000;">&#40;</span>m_startingHeight <span style="color: #000000; font-weight: bold;">+</span> m_blockLength <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>m_blockLength<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> m_overlap<span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> physScale<span style="color: #000000;">&#41;</span>;
				bd.isBullet = <span style="color: #0033ff; font-weight: bold;">false</span>;
				bd.linearDamping = <span style="color: #000000; font-weight:bold;">0.1</span>;
				bd.angularDamping = <span style="color: #000000; font-weight:bold;">0.5</span>;
				body = world.CreateBody<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span>;
				body.CreateShape<span style="color: #000000;">&#40;</span>cd<span style="color: #000000;">&#41;</span>;
				body.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
				anchor.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span> <span style="color: #000000; font-weight: bold;">/</span> physScale, <span style="color: #000000;">&#40;</span>m_startingHeight <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>m_blockLength<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> m_overlap<span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> physScale<span style="color: #000000;">&#41;</span>;
&nbsp;
				jd.Initialize<span style="color: #000000;">&#40;</span>prevBody, body, anchor<span style="color: #000000;">&#41;</span>;
&nbsp;
				world.CreateJoint<span style="color: #000000;">&#40;</span>jd<span style="color: #000000;">&#41;</span>;
&nbsp;
				prevBody = body;
			<span style="color: #000000;">&#125;</span>
			bd.linearDamping = <span style="color: #000000; font-weight:bold;">0</span>;
			bd.angularDamping = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #009900;">//bd.isBullet = true;</span>
			bd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000; font-weight: bold;">/</span>physScale, <span style="color: #000000;">&#40;</span>m_startingHeight <span style="color: #000000; font-weight: bold;">+</span> m_blockLength <span style="color: #000000; font-weight: bold;">+</span> m_blockLength<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">*</span>numPlanks <span style="color: #000000; font-weight: bold;">-</span> m_overlap<span style="color: #000000; font-weight: bold;">*</span>numPlanks<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> physScale<span style="color: #000000;">&#41;</span>;
			body = world.CreateBody<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span>;
			body.CreateShape<span style="color: #000000;">&#40;</span>sd<span style="color: #000000;">&#41;</span>;
			body.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			m_rightHook = body;
			anchor.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span> <span style="color: #000000; font-weight: bold;">/</span> physScale, <span style="color: #000000;">&#40;</span>m_startingHeight <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>m_blockLength<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">*</span>numPlanks<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> m_overlap<span style="color: #000000; font-weight: bold;">*</span>numPlanks<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> physScale<span style="color: #000000;">&#41;</span>;
			jd.Initialize<span style="color: #000000;">&#40;</span>prevBody, body, anchor<span style="color: #000000;">&#41;</span>;
			world.CreateJoint<span style="color: #000000;">&#40;</span>jd<span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> IsAttachable<span style="color: #000000;">&#40;</span>body<span style="color: #000000; font-weight: bold;">:</span>b2Body<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>body == m_leftHook <span style="color: #000000; font-weight: bold;">||</span> body == m_rightHook<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">//======================</span>
	<span style="color: #009900;">// Member Data</span>
	<span style="color: #009900;">//======================</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_blockLength<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_blockWidth<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_circleRadius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_overlap<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_startingHeight<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_leftHook<span style="color: #000000; font-weight: bold;">:</span>b2Body;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_rightHook<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Creating a bead class that could be placed on the necklace was one thing I was unsure of how to do initially.  The end result for my prototype was to create three circle shapes on a single body and to make the center one a sensor.  A sensor is something that can collide with other objects but doesn&#8217;t cause any actual physical response.  It is essentially not collidable but still keeps track of its collisions.</p>
<p>So the constructor creates this complex body.  I found very little documentation on how to make a simple complex body out of simple shapes online.  It was very easy though and if you look at the bead.as constructor you can see how I did it.  The most confusing part was how I was supposed to offset the different shapes in the body.  This is accomplished via the Shape class&#8217; localPosition attribute.  By modifying this attribute I could offset the shape in the body it will eventually be a part of.</p>
<p>The last thing in this class is the setCollidable function.  I needed a way to easily make all of the parts of the bead a sensor temporarily.  This was so that the user could drag the bead and not collide with anything and then let go and it would become collidable again.<br />
<strong>Bead.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Contacts.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Bead<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Bead<span style="color: #000000;">&#40;</span>world<span style="color: #000000; font-weight: bold;">:</span>b2World, physScale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
		m_circleRadius = radius;
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> cd<span style="color: #000000; font-weight: bold;">:</span>b2CircleDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		cd.density = <span style="color: #000000; font-weight:bold;">0.01</span>;
		cd.radius = <span style="color: #000000;">&#40;</span>m_circleRadius<span style="color: #000000;">&#41;</span>;
		cd.friction = <span style="color: #000000; font-weight:bold;">0.1</span>;
		cd.restitution = <span style="color: #000000; font-weight:bold;">0.1</span>;
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> bd<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		cd.localPosition.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">15</span> <span style="color: #000000; font-weight: bold;">/</span> physScale;
&nbsp;
		bd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000; font-weight: bold;">/</span>physScale, <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000; font-weight: bold;">/</span>physScale<span style="color: #000000;">&#41;</span>
		bd.isBullet = <span style="color: #0033ff; font-weight: bold;">true</span>;
		m_body = world.CreateBody<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span>;
		m_body.CreateShape<span style="color: #000000;">&#40;</span>cd<span style="color: #000000;">&#41;</span>;
		cd.localPosition.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">15</span> <span style="color: #000000; font-weight: bold;">/</span> physScale;
		m_body.CreateShape<span style="color: #000000;">&#40;</span>cd<span style="color: #000000;">&#41;</span>;
		cd.localPosition.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">0</span>;
		cd.isSensor = <span style="color: #0033ff; font-weight: bold;">true</span>;
		m_centerShape = m_body.CreateShape<span style="color: #000000;">&#40;</span>cd<span style="color: #000000;">&#41;</span>;
		m_body.SetMassFromShapes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> SetCollidable<span style="color: #000000;">&#40;</span>toggle<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> currentShape<span style="color: #000000; font-weight: bold;">:</span>b2Shape = m_body.GetShapeList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>currentShape; currentShape; currentShape = currentShape.m_next<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>currentShape == m_centerShape<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">continue</span>;
			<span style="color: #000000;">&#125;</span>
			currentShape.m_isSensor = <span style="color: #000000; font-weight: bold;">!</span>toggle;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">//======================</span>
	<span style="color: #009900;">// Member Data</span>
	<span style="color: #009900;">//======================</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_circleRadius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_position<span style="color: #000000; font-weight: bold;">:</span>b2Vec2;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_centerShape<span style="color: #000000; font-weight: bold;">:</span>b2Shape;
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The hook class is very simple and just creates a circle in the location where it is supposed to be.  I temporarily just used the physics circle to make it easy to test.  I don&#8217;t plan to have a physics body be the connector piece in the future unless I am using so sort of callback function.  I think it is easy enough to use the isTouching function to check if a body is within touching range of this hook.<br />
<strong>Hook.as</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.Contacts.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #000000; font-weight: bold;">*</span>;
<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Hook<span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Hook<span style="color: #000000;">&#40;</span>world<span style="color: #000000; font-weight: bold;">:</span>b2World, physScale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,  <span style="color: #004993;">position</span><span style="color: #000000; font-weight: bold;">:</span>b2Vec2, radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
		m_circleRadius = radius;
		m_position = <span style="color: #004993;">position</span>;
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> cd<span style="color: #000000; font-weight: bold;">:</span>b2CircleDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			cd.density = <span style="color: #000000; font-weight:bold;">1.0</span>;
			cd.radius = <span style="color: #000000;">&#40;</span>m_circleRadius<span style="color: #000000;">&#41;</span>;
			cd.isSensor = <span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> bd<span style="color: #000000; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			bd.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>m_position.<span style="color: #004993;">x</span>, m_position.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>
			m_body = world.CreateBody<span style="color: #000000;">&#40;</span>bd<span style="color: #000000;">&#41;</span>;
			m_body.CreateShape<span style="color: #000000;">&#40;</span>cd<span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> IsTouching<span style="color: #000000;">&#40;</span>body<span style="color: #000000; font-weight: bold;">:</span>b2Body<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">position</span> = body.GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Copy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #004993;">position</span>.Subtract<span style="color: #000000;">&#40;</span>m_position<span style="color: #000000;">&#41;</span>;
		<span style="color: #004993;">position</span>.Abs<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">position</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; x units away.&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;radius of circle is &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> m_circleRadius<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">position</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; m_circleRadius <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #004993;">position</span>.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt; m_circleRadius<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #009900;">//======================</span>
	<span style="color: #009900;">// Member Data</span>
	<span style="color: #009900;">//======================</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_circleRadius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_position<span style="color: #000000; font-weight: bold;">:</span>b2Vec2;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> m_body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The resulting application turned out pretty good.  I was not totally satisfied with placing a bead on the necklace, but I ran out of time and had to do real work by that time.  I think I could make the bead automatically orient correctly and highlight itself when it is being placed on the right spot on the necklace.  Besides that problem I am satisfied with the it as a prototype for a future application I might develop.</p>
<p>Here it is:</p>
<p><strong>Beadr Prototype 1:</strong></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_beadr_691326167"
			class="flashmovie"
			width="600"
			height="400">
	<param name="movie" value="http://chase.ratchetsoftware.com/media/beadr.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://chase.ratchetsoftware.com/media/beadr.swf"
			name="fm_beadr_691326167"
			width="600"
			height="400">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chase.ratchetsoftware.com/2008/09/necklace-simulation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

