Detect overlap of point and Shape
Hey guys,
I'm making a simple game where circles are created and you have to click on them to get rid of them. I've got the code for creating them and that works ok, and I add them all to an array when they are created.
However, I'm not sure how to detect whether the point where you click is on a shape or not. Here's the code, I have a "??????" where I don't know how to do it
----------------------------------------------------------------------------------------------------------------------------------
package
{
import flash.display.MovieClip;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.display.DisplayObject;
public class Main extends MovieClip
{
var coolDown:Timer;
var circleArray:Array;
public function Main()
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);
coolDown = new Timer (1000, 1);
coolDown.addEventListener(TimerEvent.TIMER_COMPLETE, timeDone);
coolDown.start();
circleArray = new Array();
}
function timeDone (e:TimerEvent):void
{
var theX:Number = (Math.round((Math.random()*450)+50));
var theY:Number = (Math.round((Math.random()*450)+50));
var circle:Shape = new Shape();
circle.graphics.beginFill((Math.random() * 0xFFFFFF), 1.0);
circle.graphics.drawCircle(0, 0, ((Math.round(Math.random() * 40)) + 20));
circle.graphics.endFill();
circle.x = theX;
circle.y = theY;
stage.addChild(circle);
circleArray.push(circle);
var xTween:Tween = new Tween(circle, "scaleX", Bounce.easeOut, 0, 1, 0.5, true);
var yTween:Tween = new Tween(circle, "scaleY", Bounce.easeOut, 0, 1, 0.5, true);
coolDown.addEventListener(TimerEvent.TIMER_COMPLETE, timeDone);
coolDown.start();
}
function mouseClick (event:MouseEvent):void
{
var themouseX:Number = new Number(mouseX);
var themouseY:Number = new Number(mouseY);
var mousePoint:Point = new Point(themouseX, themouseY);
var i = new int();
for each (var circle in circleArray)
{
???????
}
}
}
}
----------------------------------------------------------------------------------------------------------------------------------
All that code seems to be working so far, I just don't know how to detect whether you are clicking on one of the circles in the array or not.
