<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: AS 3.0 HitTest</title>
	<atom:link href="http://www.tink.ws/blog/as-30-hittest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tink.ws/blog/as-30-hittest/</link>
	<description>Flash Platform development and personal rants.</description>
	<lastBuildDate>Fri, 12 Mar 2010 03:03:46 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: InteractiveChaos</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202941</link>
		<dc:creator>InteractiveChaos</dc:creator>
		<pubDate>Wed, 03 Mar 2010 01:34:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202941</guid>
		<description>Awesome work - I have had issues with loading a SWF into a MC, as the hittest is offset, and therefore doesnt work. By adding Pauls suggestion of

if( !target1.stage &#124;&#124; !target2.stage &#124;&#124; !target1.hitTestObject( target2 ) ) return new Rectangle();

// Get the bounds of each DisplayObject.
var bounds1:Rectangle = target1.getBounds( target1.stage );
var bounds2:Rectangle = target2.getBounds( target2.stage );

It now works perfectly.

Nice one people.

Happy flashing</description>
		<content:encoded><![CDATA[<p>Awesome work &#8211; I have had issues with loading a SWF into a MC, as the hittest is offset, and therefore doesnt work. By adding Pauls suggestion of</p>
<p>if( !target1.stage || !target2.stage || !target1.hitTestObject( target2 ) ) return new Rectangle();</p>
<p>// Get the bounds of each DisplayObject.<br />
var bounds1:Rectangle = target1.getBounds( target1.stage );<br />
var bounds2:Rectangle = target2.getBounds( target2.stage );</p>
<p>It now works perfectly.</p>
<p>Nice one people.</p>
<p>Happy flashing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony Cholmondeley</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202939</link>
		<dc:creator>Anthony Cholmondeley</dc:creator>
		<pubDate>Tue, 02 Mar 2010 21:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202939</guid>
		<description>Tink, you saved my sanity ... Thanks for the hard work!!!</description>
		<content:encoded><![CDATA[<p>Tink, you saved my sanity &#8230; Thanks for the hard work!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Snodgrass</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202837</link>
		<dc:creator>Christian Snodgrass</dc:creator>
		<pubDate>Wed, 24 Feb 2010 04:21:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202837</guid>
		<description>It may be eluding me, but why in intersectionRectangle did you build your own intersection rectangle instead of just calling bounds1.intersection(bounds2)?

Is there some performance boost, or just because you wanted to?</description>
		<content:encoded><![CDATA[<p>It may be eluding me, but why in intersectionRectangle did you build your own intersection rectangle instead of just calling bounds1.intersection(bounds2)?</p>
<p>Is there some performance boost, or just because you wanted to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Piano Chords</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202331</link>
		<dc:creator>Piano Chords</dc:creator>
		<pubDate>Mon, 01 Feb 2010 18:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202331</guid>
		<description>How do you enable &quot;view Source&quot; for flash projects?  I did a quick google search and didn&#039;t see anything.</description>
		<content:encoded><![CDATA[<p>How do you enable &#8220;view Source&#8221; for flash projects?  I did a quick google search and didn&#8217;t see anything.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Piano Chords</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202330</link>
		<dc:creator>Piano Chords</dc:creator>
		<pubDate>Mon, 01 Feb 2010 18:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202330</guid>
		<description>Thanks a bundle!  Your hit test did the trick when my client said the hitTest wasn&#039;t accurate.  It&#039;s insane that Flash doesn&#039;t have a built in complex hit test?  Or am I missing something?  In AS2 wasn&#039;t there a shapeFlag hit test?  I don&#039;t know why they don&#039;t have something like that built in for AS3!</description>
		<content:encoded><![CDATA[<p>Thanks a bundle!  Your hit test did the trick when my client said the hitTest wasn&#8217;t accurate.  It&#8217;s insane that Flash doesn&#8217;t have a built in complex hit test?  Or am I missing something?  In AS2 wasn&#8217;t there a shapeFlag hit test?  I don&#8217;t know why they don&#8217;t have something like that built in for AS3!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stesha D</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202206</link>
		<dc:creator>Stesha D</dc:creator>
		<pubDate>Thu, 28 Jan 2010 01:29:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202206</guid>
		<description>Fantastic code! Good job.</description>
		<content:encoded><![CDATA[<p>Fantastic code! Good job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Reynolds</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202084</link>
		<dc:creator>Ian Reynolds</dc:creator>
		<pubDate>Fri, 22 Jan 2010 21:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202084</guid>
		<description>Hi-
I posted a while back asking for permission to use this class in a game engine I was building and you might be interested in seeing how useful it was to me. Check out flyte-engine.org if you&#039;re curious. Your class has been renamed Collision, I hope that&#039;s all right. Thanks a lot!</description>
		<content:encoded><![CDATA[<p>Hi-<br />
I posted a while back asking for permission to use this class in a game engine I was building and you might be interested in seeing how useful it was to me. Check out flyte-engine.org if you&#8217;re curious. Your class has been renamed Collision, I hope that&#8217;s all right. Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick A</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-202078</link>
		<dc:creator>Nick A</dc:creator>
		<pubDate>Fri, 22 Jan 2010 13:45:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-202078</guid>
		<description>I love the possibilities that are opened up with this. 

I used it with an inverted track clip and a sleigh for our companies viral campaign (http://www.d2digital.co.uk/viral.aspx) to test for the sleigh crashing into the side of the road.

I posted the car/sleigh script on my blog; http://www.d2digital.co.uk/blog/actionscript_3_code_for_a_2d_driving_car.aspx

Good work and thanks for enabling us to do much more cool stuff!

Nick</description>
		<content:encoded><![CDATA[<p>I love the possibilities that are opened up with this. </p>
<p>I used it with an inverted track clip and a sleigh for our companies viral campaign (<a href="http://www.d2digital.co.uk/viral.aspx" rel="nofollow">http://www.d2digital.co.uk/viral.aspx</a>) to test for the sleigh crashing into the side of the road.</p>
<p>I posted the car/sleigh script on my blog; <a href="http://www.d2digital.co.uk/blog/actionscript_3_code_for_a_2d_driving_car.aspx" rel="nofollow">http://www.d2digital.co.uk/blog/actionscript_3_code_for_a_2d_driving_car.aspx</a></p>
<p>Good work and thanks for enabling us to do much more cool stuff!</p>
<p>Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-201977</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Mon, 18 Jan 2010 19:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-201977</guid>
		<description>If I use this class in a SWF (say, to hit test 2 squares) and then load that SWF into another SWF at a y or x of anything but zero, it seems to break.

Example:
var loader:Loader = new Loader();
loader.load(new URLRequest(&quot;HitTest.swf&quot;));
loader.y = 200;
addChild(loader);

in order to fix this I had to change 
if( !target1.root &#124;&#124; !target2.root &#124;&#124; !target1.hitTestObject( target2 ) ) return new Rectangle();

// Get the bounds of each DisplayObject.
var bounds1:Rectangle = target1.getBounds( target1.root );
var bounds2:Rectangle = target2.getBounds( target2.root );

to

if( !target1.stage &#124;&#124; !target2.stage &#124;&#124; !target1.hitTestObject( target2 ) ) return new Rectangle();
			
// Get the bounds of each DisplayObject.
var bounds1:Rectangle = target1.getBounds( target1.stage );
var bounds2:Rectangle = target2.getBounds( target2.stage );

which messes up the intersectionRectangle function iff I wanted to use that for anything beyond internal use for the HitTest class.  Lucky for me, I don&#039;t need that for anything else.

I&#039;m not going to try and fix this any further, but I thought you might be interested.</description>
		<content:encoded><![CDATA[<p>If I use this class in a SWF (say, to hit test 2 squares) and then load that SWF into another SWF at a y or x of anything but zero, it seems to break.</p>
<p>Example:<br />
var loader:Loader = new Loader();<br />
loader.load(new URLRequest(&#8220;HitTest.swf&#8221;));<br />
loader.y = 200;<br />
addChild(loader);</p>
<p>in order to fix this I had to change<br />
if( !target1.root || !target2.root || !target1.hitTestObject( target2 ) ) return new Rectangle();</p>
<p>// Get the bounds of each DisplayObject.<br />
var bounds1:Rectangle = target1.getBounds( target1.root );<br />
var bounds2:Rectangle = target2.getBounds( target2.root );</p>
<p>to</p>
<p>if( !target1.stage || !target2.stage || !target1.hitTestObject( target2 ) ) return new Rectangle();</p>
<p>// Get the bounds of each DisplayObject.<br />
var bounds1:Rectangle = target1.getBounds( target1.stage );<br />
var bounds2:Rectangle = target2.getBounds( target2.stage );</p>
<p>which messes up the intersectionRectangle function iff I wanted to use that for anything beyond internal use for the HitTest class.  Lucky for me, I don&#8217;t need that for anything else.</p>
<p>I&#8217;m not going to try and fix this any further, but I thought you might be interested.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: magicianseeker</title>
		<link>http://www.tink.ws/blog/as-30-hittest/#comment-201850</link>
		<dc:creator>magicianseeker</dc:creator>
		<pubDate>Mon, 11 Jan 2010 12:22:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.tink.ws/blog/as-30-hittest/#comment-201850</guid>
		<description>Tink, do you know how to solve this? I used two displayObject to detect either they collide or not and it returned sometimes true sometimes false. It doesn&#039;t a problem when they are far apart--it returns true but it&#039;s like that when they are near.

btw, the displayObject are vector image.
here is the code:

public static function isHitting(hitter:DisplayObject,hittee:DisplayObject,parent:DisplayObject,precision:Number):Boolean
		{		if(hittee.hitTestObject(hitter))
			{				
				
				var rect1:Rectangle = hitter.getBounds(parent);		
				var rect2:Rectangle = hittee.getBounds(parent);
				var rectInt:Rectangle = rect1.intersection(rect2);
return searchCommon(hitter,hittee,rectInt,parent,precision)
			}
			else
			{
				return false;
			}
		}
		
		public static function searchCommon(object1:DisplayObject,object2:DisplayObject,rect:Rectangle,parent:DisplayObject,precision:Number):Boolean 
		{
			var returnValue:Boolean = false;
			var p:Point = new Point();
			for (var j:int = rect.y; j &lt;= rect.y +rect.height &amp;&amp; returnValue == false; j+=precision) {
				if (returnValue == true) {
					break;
				} 
				else {
					for (var i:int = rect.x; i &lt;= rect.x + rect.width; i+=precision) {
						p.x = i;
						p.y = j;
						p = parent.localToGlobal(p);
					
						if(object1.hitTestPoint(p.x,p.y, true) == true &amp;&amp; object2.hitTestPoint(p.x,p.y, true) == true)
						{
							returnValue = true;
							break;
						}
					}
				}
			}			
			return returnValue;
		}</description>
		<content:encoded><![CDATA[<p>Tink, do you know how to solve this? I used two displayObject to detect either they collide or not and it returned sometimes true sometimes false. It doesn&#8217;t a problem when they are far apart&#8211;it returns true but it&#8217;s like that when they are near.</p>
<p>btw, the displayObject are vector image.<br />
here is the code:</p>
<p>public static function isHitting(hitter:DisplayObject,hittee:DisplayObject,parent:DisplayObject,precision:Number):Boolean<br />
		{		if(hittee.hitTestObject(hitter))<br />
			{				</p>
<p>				var rect1:Rectangle = hitter.getBounds(parent);<br />
				var rect2:Rectangle = hittee.getBounds(parent);<br />
				var rectInt:Rectangle = rect1.intersection(rect2);<br />
return searchCommon(hitter,hittee,rectInt,parent,precision)<br />
			}<br />
			else<br />
			{<br />
				return false;<br />
			}<br />
		}</p>
<p>		public static function searchCommon(object1:DisplayObject,object2:DisplayObject,rect:Rectangle,parent:DisplayObject,precision:Number):Boolean<br />
		{<br />
			var returnValue:Boolean = false;<br />
			var p:Point = new Point();<br />
			for (var j:int = rect.y; j &lt;= rect.y +rect.height &amp;&amp; returnValue == false; j+=precision) {<br />
				if (returnValue == true) {<br />
					break;<br />
				}<br />
				else {<br />
					for (var i:int = rect.x; i &lt;= rect.x + rect.width; i+=precision) {<br />
						p.x = i;<br />
						p.y = j;<br />
						p = parent.localToGlobal(p);</p>
<p>						if(object1.hitTestPoint(p.x,p.y, true) == true &amp;&amp; object2.hitTestPoint(p.x,p.y, true) == true)<br />
						{<br />
							returnValue = true;<br />
							break;<br />
						}<br />
					}<br />
				}<br />
			}<br />
			return returnValue;<br />
		}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
