<?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>manewc &#187; HitTest Methods</title>
	<atom:link href="http://manewc.com/category/actionscript-hittest/feed/" rel="self" type="application/rss+xml" />
	<link>http://manewc.com</link>
	<description>iPhone, Flash, Flex, AIR, &#38; Web Development</description>
	<lastBuildDate>Sat, 31 Oct 2009 16:47:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[AS 3] Simple Hit Test with hitTestPoint Method</title>
		<link>http://manewc.com/2008/01/16/as-3-simple-hit-test-with-hittestpoint-method/</link>
		<comments>http://manewc.com/2008/01/16/as-3-simple-hit-test-with-hittestpoint-method/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 20:28:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[HitTest Methods]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/16/as-3-simple-hit-test-with-hittestpoint-method/</guid>
		<description><![CDATA[DisplayObject.hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false)
This method is great for testing intersections with an X,Y point of the stage. Ideally you would use this with small objects to allow for a more realistic hit test.
I used my circle class from earlier.

package {
     import flash.display.Sprite;  

     public class [...]]]></description>
			<content:encoded><![CDATA[<p>DisplayObject.hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false)</p>
<p>This method is great for testing intersections with an X,Y point of the stage. Ideally you would use this with small objects to allow for a more realistic hit test.</p>
<p>I used my circle class from earlier.</p>
<pre name="code" class="c-sharp">
package {
     import flash.display.Sprite;  

     public class Circle extends Sprite {
        private var radius:Number;
        private var color:uint;

		private var xcircle:Number;
		private var ycircle:Number;

		public function Circle(radius:Number=20, color:uint=0x336699, xcircle:Number = 10, ycircle:Number = 20) {
			this.x = xcircle;
            this.y = ycircle;
			this.radius = radius;
			this.color = color;

            draw();
		}

		public function draw(){
			graphics.beginFill(color);
            graphics.drawCircle(0, 0, radius);
            graphics.endFill();
		}
	}
}</pre>
<p>Now my document class for the hitTestObject method</p>
<pre name="code" class="c-sharp">
package {
     import flash.display.Sprite;
	 import flash.events.Event;

     public class HitTestPoint extends Sprite {
		private var circle:Circle;
		private var circle2:Circle;

		private var radius:Number;
		private var color:uint;

		private var xcircle:Number;
		private var ycircle:Number;

		public function HitTestPoint(){
			init()
		}

		public function init(){
			// CIRCLE 1
			// draw the first circle and center it on the stage
			circle = new Circle(30,0x333333,stage.stageWidth/2, stage.stageHeight/2);
			// display the circle
			addChild(circle);
			circle.startDrag(true);

			// CIRCLE 2
			circle2 = new Circle(4,0x000000,200,200);
			// display the circle
			addChild(circle2);
			circle2.alpha = 10;

			// create the listeners
			addEventListener(Event.ENTER_FRAME, testHit);
		}

		private function testHit(e:Event):void
		{
			// hit point area is x = 200 and y = 200
			if(circle.hitTestPoint(200, 200, false))
				trace ("HIT !!!!");
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/16/as-3-simple-hit-test-with-hittestpoint-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS 3] Simple Hit Test Class Using HitTestObject Method</title>
		<link>http://manewc.com/2008/01/14/as-3-simple-hittest-method/</link>
		<comments>http://manewc.com/2008/01/14/as-3-simple-hittest-method/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 18:15:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[HitTest Methods]]></category>

		<guid isPermaLink="false">http://manewc.com/2008/01/14/as-3-simple-hittest-method/</guid>
		<description><![CDATA[There are many levels of detection for testing whether one object is hitting (touching) another object. The most simple method is to use the hitTestObject method of Actionscript. This is a great method for renderings that will fit within a square/rectangular area, as you can see from the image that a circle&#8217;s area is defined [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/2008/01/hittablearea.gif" alt="hittable area" class="imgright" height="80" width="80" />There are many levels of detection for testing whether one object is hitting (touching) another object. The most simple method is to use the hitTestObject method of Actionscript. This is a great method for renderings that will fit within a square/rectangular area, as you can see from the image that a circle&#8217;s area is defined by the bounding box.</p>
<p>To start I used this Circle.as file for my circle class</p>
<pre name="code" class="c-sharp">
package {
     import flash.display.Sprite;  

     public class Circle extends Sprite {
        private var radius:Number;
        private var color:uint;

		private var xcircle:Number;
		private var ycircle:Number;

		public function Circle(radius:Number=20, color:uint=0x336699, xcircle:Number = 10, ycircle:Number = 20) {
			this.x = xcircle;
            this.y = ycircle;
			this.radius = radius;
			this.color = color;

            draw();
		}

		public function draw(){
			graphics.beginFill(color);
            graphics.drawCircle(0, 0, radius);
            graphics.endFill();
		}
	}
}</pre>
<p>&#8230; and here is the document class:</p>
<pre name="code" class="c-sharp">
package {
     import flash.display.Sprite;

	 import flash.events.Event;
	 import flash.events.MouseEvent;

     public class HitTest extends Sprite {
		private var circleOne:Circle;
		private var circleTwo:Circle;

		private var radius:Number;
		private var color:uint;

		private var xcircle:Number;
		private var ycircle:Number;

		public function HitTest(){
			init()
		}

		public function init(){
			// CIRCLE 1
			// draw the first circle and center it on the stage
			circleOne = new Circle(30,0x333333,stage.stageWidth/2, stage.stageHeight/2);
			// display the circle
			addChild(circleOne);

			// CIRCLE 2
			// draw the second circle and put in the top left corner
			circleTwo = new Circle(20,0x123456,20,20);
			// display the circle
			addChild(circleTwo);
			// make it draggable
			circleTwo.startDrag(true);

			// LISTENERS

			// create the listeners
			stage.addEventListener(MouseEvent.MOUSE_DOWN, testHit);
		}

		private function testHit(m:MouseEvent):void
		{
			if(circleTwo.hitTestObject(circleOne))
				trace ("HIT !!!!");
		}
	}
}</pre>
<p>To run the files, all you need to do is drag the one circle and then left click to determine if the two objects are colliding</p>
]]></content:encoded>
			<wfw:commentRss>http://manewc.com/2008/01/14/as-3-simple-hittest-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
